Replies: 1 comment 2 replies
-
Here's an example that does what you're asking. // Helper function that uses results from `matchRoutes`
// and builds up the path by navigating the route config
function getRouteMatchPath(
routes: RouteObject[],
location: Partial<Location> | string
) {
const matches = matchRoutes(routes, location);
const getPath = (route: RouteObject) => {
let path = route.path!;
if (route.children?.length) {
path += getPath(route.children[0]);
}
return path;
};
if (matches?.length) {
return getPath(matches[0].route);
}
return null;
} https://stackblitz.com/edit/github-vr2mys?file=src%2Fapp.tsx |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
What is the way to get the matched route using react-router?
For example,
user.jsx
Like above,
I want to get the string before the pattern like /user/:id is interpreted.
Beta Was this translation helpful? Give feedback.
All reactions