-
-
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
Revisit how splats and repeated URL parameters work #2422
Comments
I don't think we need to make |
What's unintuitive to me is that
I don't know that this would ever be what I want. |
You're right. The difference here is between greedy and non-greedy. We need a non-greedy version of |
I think the point I want to make is that the relevant distinction shouldn't be greedy vs non-greedy - it should be whether the splat matches path delimiters. At https://github.com/rackt/react-router/blob/fbc109c0218508a301caae36469c8fc5d70de5fa/modules/PatternUtils.js#L26-L31, the most straightforward approach would be to have the pattern for |
I'm actually more bothered by the repeated parameter thing, BTW. If I have something like: <Route path="/:foo" component={Parent}>
<Route path=":foo" component={Child} />
</Route> Then if I'm on This example is contrived, but I'm afraid of users accidentally hitting this on e.g. deep, asynchronous routes where it's not as obvious that a route parameter name might be getting reused. |
Maybe outputting a warning when a parameter name is used twice? |
I'd just throw while validating routes, once we have something in place for e.g. matching files with extensions so we don't need splats any more. |
In our application, a given route component might be used as a sub-route in many different places, so it has no way of knowing in which parent routes it will be used. Consequently, there is always a chance of param name clashes between it and its parent routes. Throwing an exception when a parameter name is used twice won't really help us. What I'd like to see instead is each route only receiving the params immediately following it, allowing params with identical names but different values to happily coexist. To illustrate: Let's say we have a route like
|
I don't think we want to support that. It's quite nice to have I do not think we should support repeated named params at all. |
We should do what Express does for splats (&c.) – use numerical indices. |
Closing this as part of #2286. |
The idea is – the choice of matching will affect splat handling anyway. |
This is a follow-up to #2286 and #2421, and continues discussion from #2401.
The current API around splats and repeated URL parameters is pretty confusing and might lead to unexpected behavior. Two issues:
.gitignore
usage,*
and**
respectively mean non-greedy and greedy splats, rather than wildcards that match or don't match across path separators, leading to unintuitive behavior per the examples in [added] Greedy splat (**) #2401 (comment)I think the best way to clean this up is:
*
and**
behave like in.gitignore
- both should be greedy, but only*
should match across path separators; this is significantly breaking, since it would mean that the recipe for a catch-all route would instead be<Route path="**" component={NotFound} />
*.*
for matching e.g. file names, instead use a custom rule per Customizable URL matching rules #2286I think this would make things simpler, eliminate potentially confusing edge cases, and make behavior more consistent with other places.
The text was updated successfully, but these errors were encountered: