-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Params constraints #4019
Comments
Isn't this already doable using <Match pattern='/posts/:id(\d+)' component={Post} /> Note: One gotcha with this is that with Babel, JSX strings are automatically escaped, so while in the <Match pattern='/posts/:id(\d+)' component={PostID} />
// becomes
React.createElement(Match, { pattern: '/posts/:id(\\d+)', component: PostID }) |
I wasn't familiar with that, but it sounds like that fits the bill. I think the other idea was if you want to do more business logic on your params, but that's best left for your child function. |
Hello! While playing with v4's alpha I found a little awkward how ambiguous matches are handled, especially when using a centralized route config.
So I thought about adding optional params constraint to
<Match>
to better handle ambiguous matches while iterating a route config.Use case
If I have these routes in my config (I know they are silly, they're just an example):
And I render them like that:
When I visit
/posts/comments
both routes will trigger.Proposal
So I propose to add
constraints
prop to<Match>
(I'm very bad at naming, couldn't figure a better one) that will also validate the params in order to match the route.Something like that:
In this way when I visit
/posts/comments
I will not have a double match anymore!Hopefully this makes sense, my english it's not very good :(
If you find this proposal somewhat interesting I could work on a PR too!
Thanks for your time and your work on this library!
The text was updated successfully, but these errors were encountered: