Is there a way to get current path pattern? #10937
Replies: 1 comment 3 replies
-
There's no built-in function to do exactly what you want, but we can create it. First of all, you'll need to define your route config as an object that you pass to Here's a sample StackBlitz that shows how it works. ⚡️ StackBlitz https://stackblitz.com/edit/github-vr2mys?file=src%2Fapp.tsx // 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;
} Footnotes |
Beta Was this translation helpful? Give feedback.
3 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.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to get current path pattern in v5?
I cannot find any function for hook to get this.
ex. When you are on "/user/1234", then you will get "/user/:id"
Or is there a way to get all path patterns from
Router
?Beta Was this translation helpful? Give feedback.
All reactions