From 698f1174c7ddac495a44152dec333188c0de8a0b Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Fri, 13 Sep 2019 17:05:36 +0300 Subject: [PATCH] urlParamsForPath function inlined in Router --- src/router/Router/Router.js | 12 ++++++++++-- src/router/Router/urlParamsForPath.js | 12 ------------ 2 files changed, 10 insertions(+), 14 deletions(-) delete mode 100644 src/router/Router/urlParamsForPath.js diff --git a/src/router/Router/Router.js b/src/router/Router/Router.js index 7b5d055bc..50bbab579 100644 --- a/src/router/Router/Router.js +++ b/src/router/Router/Router.js @@ -4,7 +4,6 @@ const PropTypes = require('prop-types'); const UrlUtils = require('url'); const Route = require('../Route'); const { RoutesContainerProvider } = require('../RoutesContainerContext'); -const urlParamsForPath = require('./urlParamsForPath'); const Router = ({ className, onPathNotMatch, ...props }) => { const [{ homePath, viewsConfig }] = React.useState(() => ({ @@ -61,7 +60,16 @@ const Router = ({ className, onPathNotMatch, ...props }) => { return; } - const urlParams = urlParamsForPath(routeConfig, pathname); + 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] = matches[index + 1]; + } else { + urlParams[name] = null; + } + + return urlParams; + }, {}); const routeViewIndex = viewsConfig.findIndex((vc) => vc.includes(routeConfig)); const routeIndex = viewsConfig[routeViewIndex].findIndex((rc) => rc === routeConfig); setViews((views) => { diff --git a/src/router/Router/urlParamsForPath.js b/src/router/Router/urlParamsForPath.js deleted file mode 100644 index d7b52aaea..000000000 --- a/src/router/Router/urlParamsForPath.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = (routeConfig, path) => { - const matches = typeof path === 'string' ? path.match(routeConfig.regexp) : []; - return routeConfig.urlParamsNames.reduce((urlParams, name, index) => { - if (Array.isArray(matches) && typeof matches[index + 1] === 'string') { - urlParams[name] = matches[index + 1]; - } else { - urlParams[name] = null; - } - - return urlParams; - }, {}); -}; \ No newline at end of file