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

Add routes in order of depth in 'on' method #39

Merged
merged 4 commits into from
Sep 13, 2016

Conversation

abradley2
Copy link
Contributor

This change means routes with deeper urls will be given priority.

From the README:

router
  .on({
    'products/:id': function () {
      setContent('Products');
    },
    'products': function () {
      setContent('About');
    },
    '*': function () {
      setContent('Home')
    }
  })
  .resolve();

It is important to add products/:id first because otherwise you may fall into products every time

This will no longer be the case. If the 'products' route is added before 'products/:id', resolving to 'products/42' will match the 'products/:id' route. When using on routes will then be added in the order of depth (number of segments in the route).

This also prevents a possible issue from looping through the 'routes' object in the 'on' method- because ECMAScript specification does not guarantee that the keys of Objects will be in order given a for-let loop.

@krasimir krasimir merged commit de50192 into krasimir:master Sep 13, 2016
@krasimir
Copy link
Owner

Thank you for the contribution. 2.3.0 released containing your fix.

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