react-router
react-router copied to clipboard
[Bug]: "*" not matching a URL with double slashes "//"
What version of React Router are you using?
6.0.2
Steps to Reproduce
- Prepare an application that uses react router v6.
- prepare a Route with a path of *.
{ path: "/", element: <Home /> }, { path: "*", element: <NotFound /> }
- access the url with multiple slashes, such as https://example.com//a
Expected Behavior
This is also happening with Remix. When accessing https://remix.run//a, the behavior is unintended. Presumably, the component specified by * should be rendrering even if an unintended url string is given.
Actual Behavior
An error occurs. I think it's because matchRoutes returns null.
I concur with this issue
i have the same problem with hashrouter -> #%2F7
What version of React Router are you using? 6.0.2
Steps to Reproduce
<HashRouter>
<Routes>
<Route element={<ProcessMap {...props}/>} />
<Route index element={<ProcessMap {...props}/>} />
<Route path="%*" element={<ProcessMap {...props}/>} />
<Route path="/" element={<ProcessMap {...props}/>} />
<Route path="/:ident" element={<ProcessPage {...props} />} />
</Routes>
</HashRouter>
Actual Behavior Browser shows blank page
console: index.js:21 No routes matched location "%2F7"
on %*
console : "index.js:21 Route path "%" will be treated as if it were "%/" because the *
character must always follow a /
in the pattern. To get rid of this warning, please change the route path to "%/*".
Expected Behavior Browser shows ProcessMap will be even happy if anything shows up
I'm running into the same issue unfortunately. I would expect * to match any value (including double slashes, if there are any). Unfortunately it either doesn't match, or returns a matched value without the double slash.
This is fixed when I remove this line: https://github.com/remix-run/react-router/blob/44fa91c2e18842dbd6cc5f77f54d51aa24a4f3b1/packages/router/utils.ts#L876
However, that causes many of the other tests to fail. I gave it a go but I lack the right understanding of the architecture to find a fix that keeps the tests stable
This doesn't appear to be an issue anymore, I was able to setup the routes in the original issue and can match /
(matches index), //
(matches index), and //abc
(matches splat) appropriately.
https://codesandbox.io/s/affectionate-dew-vzfdmq
I'm going to close this out, but if there is still a specific issue, please open a new issue with a reproduction.
this does not work with loading https://github.com/remix-run/react-router/issues/8428