Params Object Accumulates With Each Attempt To Match A Route #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I just submitted another pull request for what looks like to be the same issue, mine is #56. The gist of it is that if Path runs through several possible routes that don't match the specified route before it finally does find the correct route. In my case it was due to the order in which I had defined my routes coupled with having mapped them in reverse using a while(i--). Due to this Path was iterating through my route definition list in reverse order, which I didn't at first think about. The problem is that all params that Path comes across with each route it attempts to match are accumulated in the params object. When it finally finds the correct route it passes the whole params object to the correct route. This params object includes any params that route expects plus any that Path came across while trying to find that route. So for example:
Let's suppose the route we're triggering is 'myOtherRoute/something', if we iterate through these in order we'll find that the params object passed to myOtherHandler is:
Obviously the problem is that myOtherHandler isn't expecting the myParam parameter. So to prevent this in the match method just after line 61 I simply added the line:
to reset the params object with each attempted route match. This way whatever route that is finally matched will only get the params it expects.