mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-05 08:29:49 +00:00
urlParamsForPath moved to separate file
This commit is contained in:
parent
49df82a2da
commit
aabca44a29
2 changed files with 16 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ const deepEqual = require('deep-equal');
|
|||
const { RouteFocusedProvider } = require('../RouteFocusedContext');
|
||||
const Route = require('../Route');
|
||||
const routeConfigForPath = require('./routeConfigForPath');
|
||||
const urlParamsForPath = require('./urlParamsForPath');
|
||||
|
||||
const Router = ({ className, onPathNotMatch, ...props }) => {
|
||||
const { homePath, viewsConfig } = React.useMemo(() => ({
|
||||
|
|
@ -52,16 +53,7 @@ const Router = ({ className, onPathNotMatch, ...props }) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const matches = pathname.match(routeConfig.regexp);
|
||||
const urlParams = routeConfig.urlParamsNames.reduce((urlParams, name, index) => {
|
||||
if (Array.isArray(matches) && typeof matches[index + 1] === 'string') {
|
||||
urlParams[name] = decodeURIComponent(matches[index + 1]);
|
||||
} else {
|
||||
urlParams[name] = null;
|
||||
}
|
||||
|
||||
return urlParams;
|
||||
}, {});
|
||||
const urlParams = urlParamsForPath(routeConfig, pathname);
|
||||
const routeViewIndex = viewsConfig.findIndex((vc) => vc.includes(routeConfig));
|
||||
const routeIndex = viewsConfig[routeViewIndex].findIndex((rc) => rc === routeConfig);
|
||||
setViews((views) => {
|
||||
|
|
|
|||
14
src/router/Router/urlParamsForPath.js
Normal file
14
src/router/Router/urlParamsForPath.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
const urlParamsForPath = (routeConfig, path) => {
|
||||
const matches = path.match(routeConfig.regexp);
|
||||
return routeConfig.urlParamsNames.reduce((urlParams, name, index) => {
|
||||
if (Array.isArray(matches) && typeof matches[index + 1] === 'string') {
|
||||
urlParams[name] = decodeURIComponent(matches[index + 1]);
|
||||
} else {
|
||||
urlParams[name] = null;
|
||||
}
|
||||
|
||||
return urlParams;
|
||||
}, {});
|
||||
};
|
||||
|
||||
module.exports = urlParamsForPath;
|
||||
Loading…
Reference in a new issue