Is there a easy way to get path pattern of current location? #10548
-
How can we get path pattern of current URL (or any other URL) easily? The only solution I find everywhere is using matchPath with list of all paths in your site and matching it with current URL to get the pattern. But it cumbersome and I don't exactly have a list of URLs in my whole site in one place. I just want to differentiate between params in URL with static parts of current path, and as the router is obviously matching the path in my routes to redirect me, I think it would already have the pattern, I just can't find where to get that pattern from. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There's no place to get it, why do you need it? What's the actual use case, maybe there's another way to do it. |
Beta Was this translation helpful? Give feedback.
A router can have a
handle
export, this export can be anything you want, is a place Remix gives you to put things associated to a route.Then in your components, you can use
useMatches
to access the currently matching routes, and this includes thehandle
.So what you can do is to add a breadcrumb property to this handle.
Then use the hook to get the matches with a handle with a breadcrumb and render the list.