-
-
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
[fixed] Match routes piece-by-piece #2421
Conversation
@@ -44,13 +44,13 @@ function getIndexRoute(route, location, callback) { | |||
} | |||
|
|||
function assignParams(params, paramNames, paramValues) { | |||
return paramNames.reduceRight(function (params, paramName, index) { | |||
return paramNames.reduce(function (params, paramName, index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a leftover from a direction I ended up abandoning, but it seems like it simplifies this function a bit to not use reduceRight
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduceRight
uses the last params first, so subsequent params that are named the same thing appear after previous values in the params array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems simpler but equivalent to use reduce
and push
over reduceRight
and unshift
, though.
Rebased. |
[fixed] Match routes piece-by-piece
thanks! |
This PR makes me nervous. No tests? What are you trying to fix? |
@knowbody Please wait for me to review stuff like this before merging! |
I did it again, I stop merging lol 🙈 |
If we have great tests around something, then merge away. But I think @taion made some changes to behavior that we don't actually have tests for. I was demo-ing the router last night to a crowd in Vancouver, and some of the examples on master are broken. So we're in danger of regressing when we make major changes like this without any tests. |
Most of the code exercised here is covered by https://github.com/rackt/react-router/blob/master/modules/__tests__/matchRoutes-test.js. I didn't get a chance to add tests for a potentially new error case, which would be something like <Route path="a">
<Route path="b" />
</Route> matching something like Are you on Discord or IRC? Might be easier to explain what this is trying to do on chat. |
Sorry, I'm busy right now. I can probably talk about this later tonight. For now, would you be ok reverting and opening another PR? |
BTW, just wanted to say thanks for working on this @taion. I don't mean to be unappreciative. It's just been really tricky to get this right, hence the subtle bugs. Whenever we're making changes around this kind of thing we need to take the time to add stringent tests, preferably the kind that fail before we make the change to the code. |
I'm okay with reverting. I believe this code works, though - I'm putting together a PR right now that adds test cases that fail against the code prior to this PR, and verifies that the new code for splitting on path separators works. |
I just realized one consequence of this change - this now causes us to normalize duplicate slashes between route segments, e.g. <Route path="/foo">
<Route path="bar" />
</Route> will now match e.g. Not sure what behavior is desirable here. |
Fixes #2355
This is mostly straightforward, except for adding some special-casing to check that we only match at path boundaries.