Skip to content
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

Fix greedy * in route paths #8052

Merged
merged 4 commits into from
Sep 20, 2021
Merged

Fix greedy * in route paths #8052

merged 4 commits into from
Sep 20, 2021

Conversation

mjackson
Copy link
Member

@mjackson mjackson commented Sep 17, 2021

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.

Breaking changes:

  • In 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 *. You can strip off params['*'] from the end of match.pathname if you need the old behavior
  • useParams() in a descendant <Routes> object no longer returns the params from its ancestor <Routes>. You can persist the params directly if you need the old behavior

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
Also, remove `pathnameStart` property from `match` objects.
@mjackson mjackson merged commit c13b669 into dev Sep 20, 2021
@mjackson mjackson deleted the splat-fixes branch September 21, 2021 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant