You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is expected that a pathname created with generatePath matches the given path in matchPath, Route etc. and yields the input parameters basically unchanged. This is not the case if a parameter contains a slash:
constpath='/a/:b/c';constb='1/2';console.log(matchPath({ path },generatePath(path,{ b })));
React example:
constpath='/a/:b/c';constparams={b: '1/2'};constMatch=()=>{const{ b }=useParams<'b'>();return<h1>Hello {b}</h1>};constTest=()=>{return(<BrowserRouter><Linkto={generatePath(path,params)}>Click me</Link><Routes><Routepath={path}element={<Match/>}/><Routepath="*"element={<h1>No match :(</h1>}/></Routes></BrowserRouter>);};
Expected Behavior
I expect the match params to be the same as the params passed to generatePath:
Worth noting that matchPath seems to work as expected and decodes %2F to /, however generatePath doesn't encode / to %2F. A workaround for this would be to use encodeURIComponent together with generatePath in cases where this is expected to happen, but actually we don't want to encode all special characters.
Another perspective would be that generatePath is working correctly but matchPath isn't, however there might be ambiguities for multiple parameters (/:foo/:bar) which would need to be ruled out by defining some lookahead logic for matching.
What version of React Router are you using?
6.26.1
Steps to Reproduce
It is expected that a pathname created with
generatePath
matches the given path inmatchPath
,Route
etc. and yields the input parameters basically unchanged. This is not the case if a parameter contains a slash:React example:
Expected Behavior
I expect the match params to be the same as the params passed to
generatePath
:React example:
Actual Behavior
null
React example:
Worth noting that
matchPath
seems to work as expected and decodes%2F
to/
, howevergeneratePath
doesn't encode/
to%2F
. A workaround for this would be to useencodeURIComponent
together withgeneratePath
in cases where this is expected to happen, but actually we don't want to encode all special characters.Another perspective would be that
generatePath
is working correctly butmatchPath
isn't, however there might be ambiguities for multiple parameters (/:foo/:bar
) which would need to be ruled out by defining some lookahead logic for matching.Related issues
navigate(obj)
#10213 (?)The text was updated successfully, but these errors were encountered: