UNPKG

@anew/router

Version:
30 lines (24 loc) 653 B
import { matchPath, Router } from 'react-router'; function matchRoutes(routes, pathname, /*not public API*/ branch) { if (branch === void 0) { branch = []; } routes.some(function (route) { var 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: route, match: match }); if (route.routes) { matchRoutes(route.routes, pathname, branch); } } return match; }); return branch; } export default matchRoutes;