-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v6] [Bug]: React Router is too greedy. /routetypo matches /route instead of the * fallback #7972
Comments
I'm not 100% sure but I think I run into a similar problem. I recently updated to
Subsequently clicking on
I reverted to |
Thanks for bringing this to our attention, @eakl. You're right, * is too greedy. I have a fix incoming for that one shortly.
In beta.4 we stopped using As for the @openscript I don't think your issue is related. In v6, all relative |
This prevents `*` from matching without a preceding `/` in the URL pathname. So e.g. `/users/*` matches `/users/mj` but not `/userstypo`. This also fixes `to="."` in splat routes so they point to the route path *including* the portion of the URL that was matched by the `*`, which also makes `*` more consistent with `:param` since it's treated just the same as any other param. There is however a subtle breaking change if you are using the low-level `match` API, e.g. the `match` object you get back from `matchRoutes()` or `useMatch()`. `match.pathname` in a splat route now includes the full URL pathname that was matched instead of only the portion before the `*`. There is a new variable, `match.pathnameStart` that you can use if you needed this for doing your own route matching. Fixes #7972
Thanks @mjackson for the fixes |
This prevents `*` from matching without a preceding `/` in the URL pathname. So e.g. `/users/*` matches `/users/mj` but not `/userstypo`. This also fixes `to="."` in splat routes so they point to the route path *including* the portion of the URL that was matched by the `*`, which also makes `*` more consistent with `:param` since it's treated just the same as any other param. There is however a subtle breaking change if you are using the low-level `match` API, e.g. the `match` object you get back from `matchRoutes()` or `useMatch()`. `match.pathname` in a splat route now includes the full URL pathname that was matched instead of only the portion before the `*`. There is a new variable, `match.pathnameStart` that you can use if you needed this for doing your own route matching. Fixes #7972
This prevents `*` from matching without a preceding `/` in the URL pathname. So e.g. `/users/*` matches `/users/mj` but not `/userstypo`. This also fixes `to="."` in splat routes so they point to the route path *including* the portion of the URL that was matched by the `*`, which also makes `*` more consistent with `:param` since it's treated just the same as any other param. There is however a subtle breaking change if you are using the low-level `match` API, e.g. the `match` object you get back from `matchRoutes()` or `useMatch()`. `match.pathname` in a splat route now includes the full URL pathname that was matched instead of only the portion before the `*`. There is a new variable, `match.pathnameStart` that you can use if you needed this for doing your own route matching. Fixes #7972
This is fixed in beta.5 https://github.com/remix-run/react-router/releases/tag/v6.0.0-beta.5 |
This version breaks the nested layout. Steps to Reproduce:
Follow in below the main structure of code. <Router>
<Link to="/home">Home</Link>
<Link to="/home/detail">Home - Detail</Link>
<Link to="/home/wrongParam">Wrong Id</Link>
<Routes>
<Route
path="/*"
element={
<div>
<h1>Root</h1>
<Routes>
<Route path="/" element={<h2>Welcome!</h2>} />
<Route path="home/">
<Route path="" element={<h2>Home</h2>} />
<Route path="detail" element={<p>Home / Detail</p>} />
</Route>
<Route path="*" element={<h2>Not Found.</h2>} />
</Routes>
</div>
}
/>
</Routes>
</Router> |
What version of React Router are you using?
6.0.0-beta.2
Steps to Reproduce
https://codesandbox.io/s/react-router-routing-j72xo?file=/src/App.js
Expected Behavior
Route path parameter is confusing
/
should match Root/home
should look to its children and match Home/hometypo
should match Not Found/home/wrongParam
should match<Navigate ... />
Actual Behavior
/
matches Root (OK)/home
looks to its children and matches Home (OK)/hometypo
matched Home (NOT OK, RR is too greedy)/home/wrongParam
redirects to<Navigate />
(OK but the redirect path is inconsistent with<Route path />
)Referring to #7335, I agree that
<Route path />
should implement a.
for the root of the subcomponent instead of the forward slash.When having
<Route path />
and<Navigate to />
side by side, it becomes confusing to match the root of the parent route with a forward slash instead of a.
The text was updated successfully, but these errors were encountered: