-
Notifications
You must be signed in to change notification settings - Fork 27.3k
refactor(ngRoute): make the order of route matching deterministic #3500
refactor(ngRoute): make the order of route matching deterministic #3500
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Even when there is a value in being explicit on the order routes should be applied, this PR breaks the ability to redefine a route. |
Previously, routes were matched against the current $location in an arbitrary order. This change ensures that routes are matched in the order they were originally configured, making it possible to specify overlapping path components which are fixed in some routes and variable in others. For example, $route.when('/Book/new', ...); $route.when('/Book/:bookId', ...); can now be used to ensure that a different route configuration is used for new books and for existing ones.
Lucas, thank you for your feedback. I was not aware that all javascript implementations consistently order properties in the order they were added. However, it would be nice to guarantee the order rather than counting on that behavior continuing. I have updated the change to ensure that when a route is redefined, redundant entries are not added to the routeOrder array. On route redefinition the new routing information is still correctly associated with the path. I've added an additional test to check that route redefinition continues to work. |
Daniel, 7ac6627 works as intended, but having |
Is this a dupe of #3602 ? |
The problem with this solution to routing precedence is that writing @btford #3602 would solve a different problem where you may want to match:
currently, the second route would never be matched. This PR would solve the problem by inverting the order of those 2 |
Lucas, I considered using a single array to hold the routes, but that would have required searching the entire array for duplicates, which seemed less desirable than the redundancy of using two data structures. The redundancy is mitigated by the fact that that both |
I'm closing this PR, because:
Basically I think that this change does not solve anything. @notNotDaniel Did you have any particular use case that didn't work for you and you were trying to fix it ? If so, please add a test for that use case. |
I'll be happy to make the changes to ensure that this builds again if there's any chance it will be accepted. |
Previously, routes were matched against the current $location in an arbitrary
order. This change ensures that routes are matched in the order they were
originally configured, making it possible to specify overlapping path
components which are fixed in some routes and variable in others. For example,
can now be used to ensure that a different route configuration is used for
new books and for existing ones.