Repository navigation
Add optional path segment support to useMatch/matchPath #9862
Replies: 7 comments 1 reply
|
I'm going to convert this to a discussion so it can go through our new Open Development process. Please upvote the new Proposal if you'd like to see this considered! |
|
I think this would be doable, but just for reference where we stand today is that the flattening happens higher in the call stack (in |
|
I just stumbled on this when I was migrating to v6 in our app. Essentially I didn't know about this until our tests started to fail. Also there is no mention of this behaviour in documentation and one would expect it to work same as |
|
Our team trying migrate to router v6 and we use |
|
For anyone that are trying to find an workaround for this issue while it's not fixed, I've been using some regex to replace optional parameter wildcards const route = '/something/:optionalPath?'
const routeToMatch = '/something/1234'
const pathPattern = route.replaceAll(/:(.*?)\?/gi, '*')
matchPattern(pathPattern, routeToMatch) |
|
Could we merge the open pr? Waiting for this change :) |
|
This is resolved by #10768 and will be available in the next release 👍 |
Uh oh!
There was an error while loading. Please reload this page.
What is the new or updated feature that you are suggesting?
Optional path segment handling in
matchPathanduseMatch.Currently it is supported in Route definitions, but not when matching an arbitrary route pattern:
Why should this feature be included?
Feature parity between how
<Route />components are defined and how direct usage ofmatchPathanduseMatchworks.All reactions