forked from cherijs/react-router-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchRoutes.js
40 lines (25 loc) · 1.06 KB
/
matchRoutes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
exports.__esModule = true;
var _matchPath = require('react-router/matchPath');
var _matchPath2 = _interopRequireDefault(_matchPath);
var _Router = require('react-router/Router');
var _Router2 = _interopRequireDefault(_Router);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// ensure we're using the exact code for default root match
var computeMatch = _Router2.default.prototype.computeMatch;
var matchRoutes = function matchRoutes(routes, pathname) {
var branch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
routes.some(function (route) {
var match = route.path ? (0, _matchPath2.default)(pathname, route) : branch.length ? branch[branch.length - 1].match // use parent match
: computeMatch(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;
};
exports.default = matchRoutes;