Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const route = routes.find(r =>
matchPath(path, _routeMatchOptions(r, matchedPath))
); // take the first match
const _resolveRouteMatches = (
routes: Array = [],
path: string = '',
matchedRoutes: Array = [],
matchedPath: string = ''
): Promise> => {
const route = routes.find(r =>
matchPath(path, _routeMatchOptions(r, matchedPath))
); // take the first match
if (!route) {
return Promise.resolve(matchedRoutes);
}
// add the route and its `match` object to the array of matched routes
const currentMatchOptions = _routeMatchOptions(route, matchedPath);
const match = matchPath(path, currentMatchOptions);
if (!match) {
// we know that this won't ever run because we've established the match in
// `.find`, but this check is for type safety
return Promise.resolve(matchedRoutes);
}
const matchedRoute = { route, match };
const currentMatchedRoutes = [...matchedRoutes, matchedRoute];
// add any nested route matches
return resolveChildRoutes(matchedRoute).then(
childRoutes =>
childRoutes.length
? _resolveRouteMatches(
childRoutes,
path,
currentMatchedRoutes,
const matches = routes.reduce((matches, route) => {
const match = matchPath(req.url, route.path, route);
if (match && match.isExact) {
const fetchData = route.component.fetchData || route.fetchData;
matches.push({
route,
match,
promise: fetchData ? fetchData({ store, params: match.params }) : Promise.resolve(),
});
}
return matches;
}, []);
.find((route) => matchPath(url, { path: route.path, exact: true, strict: false }));
}
topRoutes.some(({ path, breadcrumb, routes }) => {
const matches = matchPath(location.pathname, path);
if (matches) {
acc.push({
breadcrumb,
pathname: generatePathname(path, matches.params),
});
generateBreadcrumbs(acc, routes, location);
}
return matches;
});
return acc;
return React.Children.toArray(children).find((child: any) => {
return matchPath(pathname, {
exact: child.props.exact,
path: child.props.path,
});
}) || NO_MATCH;
}
.forEach((route) => {
const match = matchPath(url, { path: route.path, exact: true, strict: false });
if (match) {
route.component.needs.forEach((need) => {
const result = need(match.params);
needs.push(dispatch(result));
});
}
});
return Promise.all(needs);