mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 23:12:13 +00:00
use match instead of exec in Router
This commit is contained in:
parent
911c62faf1
commit
a9eaf1c7d2
1 changed files with 9 additions and 9 deletions
|
|
@ -13,11 +13,13 @@ const Router = ({ homePath, viewsConfig, onPathNotMatch }) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const routeConfigForPath = React.useCallback((path) => {
|
const routeConfigForPath = React.useCallback((path) => {
|
||||||
for (const viewConfig of viewsConfig) {
|
if (typeof path === 'string') {
|
||||||
for (const routeConfig of viewConfig) {
|
for (const viewConfig of viewsConfig) {
|
||||||
const match = routeConfig.regexp.exec(path);
|
for (const routeConfig of viewConfig) {
|
||||||
if (match) {
|
const match = path.match(routeConfig.regexp);
|
||||||
return routeConfig;
|
if (match) {
|
||||||
|
return routeConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +38,7 @@ const Router = ({ homePath, viewsConfig, onPathNotMatch }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const routeViewIndex = viewsConfig.findIndex((v) => v.includes(routeConfig));
|
const routeViewIndex = viewsConfig.findIndex((v) => v.includes(routeConfig));
|
||||||
const match = routeConfig.regexp.exec(pathname);
|
const match = pathname.match(routeConfig.regexp);
|
||||||
const queryParams = Array.from(new URLSearchParams(query !== null ? query : '').entries())
|
const queryParams = Array.from(new URLSearchParams(query !== null ? query : '').entries())
|
||||||
.reduce((result, [key, value]) => {
|
.reduce((result, [key, value]) => {
|
||||||
result[key] = value;
|
result[key] = value;
|
||||||
|
|
@ -108,9 +110,7 @@ Router.propTypes = {
|
||||||
homePath: PropTypes.string,
|
homePath: PropTypes.string,
|
||||||
onPathNotMatch: PropTypes.func,
|
onPathNotMatch: PropTypes.func,
|
||||||
viewsConfig: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.exact({
|
viewsConfig: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.exact({
|
||||||
regexp: PropTypes.shape({
|
regexp: PropTypes.instanceOf(RegExp).isRequired,
|
||||||
exec: PropTypes.func.isRequired
|
|
||||||
}).isRequired,
|
|
||||||
keys: PropTypes.arrayOf(PropTypes.shape({
|
keys: PropTypes.arrayOf(PropTypes.shape({
|
||||||
name: PropTypes.string.isRequired
|
name: PropTypes.string.isRequired
|
||||||
})).isRequired,
|
})).isRequired,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue