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! |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Our team trying migrate to router v6 and we use |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
Could we merge the open pr? Waiting for this change :) |
Beta Was this translation helpful? Give feedback.
-
This is resolved by #10768 and will be available in the next release 👍 |
Beta Was this translation helpful? Give feedback.
-
What is the new or updated feature that you are suggesting?
Optional path segment handling in
matchPath
anduseMatch
.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 ofmatchPath
anduseMatch
works.Beta Was this translation helpful? Give feedback.
All reactions