Replies: 1 comment 1 reply
-
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.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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