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

Params Object Accumulates With Each Attempt To Match A Route #57

Closed
wants to merge 1 commit into from

Conversation

tkw722
Copy link

@tkw722 tkw722 commented Mar 19, 2013

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:

var myRegisteredRoutes = [
    ['myRoute/:myParam', myHandler]
    ['myOtherRoute/:myOtherParam', myOtherHandler]
];

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:

{
    myParam: 'something',
    myOtherParam: 'something'
}

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:

params = {};

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.

… Otherwise params accumulate with each attempted match.
@olivM
Copy link

olivM commented Jun 5, 2013

i got the same issue.
does anyone know if the pull request is planned to be accepted ?

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.

2 participants