How to use the react-router-dom/matchPath function in react-router-dom

To help you get started, we’ve selected a few react-router-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meetup / meetup-web-platform / packages / mwp-router / src / util / resolve.js View on Github external
const route = routes.find(r =>
		matchPath(path, _routeMatchOptions(r, matchedPath))
	); // take the first match
github meetup / meetup-web-platform / packages / mwp-router / src / util / resolve.js View on Github external
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,
github strues / react-universal-boiler / src / entry / server.js View on Github external
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;
  }, []);
github peter-mouland / react-lego / src / server / middleware / set-router-context.jsx View on Github external
    .find((route) => matchPath(url, { path: route.path, exact: true, strict: false }));
}
github strues / boldr / packages / frontend / src / scenes / Admin / components / Breadcrumbs / Breadcrumbs.js View on Github external
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;
github IronPans / bee-mobile / src / components / Router / AnimatedSwitch.tsx View on Github external
return React.Children.toArray(children).find((child: any) => {
                return matchPath(pathname, {
                    exact: child.props.exact,
                    path: child.props.path,
                });
            }) || NO_MATCH;
    }
github peter-mouland / react-lego / src / server / middleware / set-router-context.jsx View on Github external
.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);