Repository URL to install this package:
|
Version:
6.0.0 ▾
|
import matchPath from 'react-router/matchPath'
import Router from 'react-router/Router'
// ensure we're using the exact code for default root match
const { computeMatch } = Router.prototype
const matchRoutes = (routes, pathname, /* not public API*/ branch = []) => {
routes.some(route => {
const match = route.path
? matchPath(pathname, route)
: branch.length
// use parent match
? branch[branch.length - 1].match
// use default "root" match
: computeMatch(pathname)
if (match) {
branch.push({ route, match })
if (route.routes) {
matchRoutes(route.routes, pathname, branch)
}
}
return match
})
return branch
}
export default matchRoutes