react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Bug]: "*" not matching a URL with double slashes "//"

Open harxki opened this issue 3 years ago • 2 comments

What version of React Router are you using?

6.0.2

Steps to Reproduce

  1. Prepare an application that uses react router v6.
  2. prepare a Route with a path of *.
    { path: "/", element: <Home /> },
    { path: "*", element: <NotFound /> }
    
  3. 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.

harxki avatar Dec 02 '21 05:12 harxki

I concur with this issue

melloware avatar Dec 02 '21 14:12 melloware

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

vreezy avatar Dec 03 '21 10:12 vreezy

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

YousefED avatar Apr 17 '23 01:04 YousefED

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.

brophdawg11 avatar Apr 28 '23 20:04 brophdawg11

this does not work with loading https://github.com/remix-run/react-router/issues/8428

fillinmar avatar Apr 04 '24 15:04 fillinmar