You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
593 B
26 lines
593 B
import { matchPath, Router } from "react-router";
|
|
|
|
function matchRoutes(routes, pathname, /*not public API*/ branch = []) {
|
|
routes.some(route => {
|
|
const match = route.path
|
|
? matchPath(pathname, route)
|
|
: branch.length
|
|
? branch[branch.length - 1].match // use parent match
|
|
: Router.computeRootMatch(pathname); // use default "root" match
|
|
|
|
if (match) {
|
|
branch.push({ route, match });
|
|
|
|
if (route.routes) {
|
|
matchRoutes(route.routes, pathname, branch);
|
|
}
|
|
}
|
|
|
|
return match;
|
|
});
|
|
|
|
return branch;
|
|
}
|
|
|
|
export default matchRoutes;
|