Skip to content

Commit

Permalink
Merge pull request angular-ui#1585 from just-boris/master
Browse files Browse the repository at this point in the history
fix($urlRouter): resolve clashing of routes
  • Loading branch information
nateabele committed Sep 23, 2015
2 parents 5910337 + b5c57c8 commit 07c046c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/urlRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
return listener;
}

rules.sort(function(ruleA, ruleB) {
var aLength = ruleA.prefix ? ruleA.prefix.length : 0;
var bLength = ruleB.prefix ? ruleB.prefix.length : 0;
return bLength - aLength;
});

if (!interceptDeferred) listen();

return {
Expand Down
14 changes: 14 additions & 0 deletions test/urlRouterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe("UrlRouter", function () {
return path.replace('baz', 'b4z');
}).when('/foo/:param', function($match) {
match = ['/foo/:param', $match];
}).when('/foo/bar', function($match) {
match = ['/foo/bar', $match];
}).when('/bar', function($match) {
match = ['/bar', $match];
});
Expand All @@ -71,6 +73,18 @@ describe("UrlRouter", function () {
});
});

it("should handle more specified url first", function() {
location.path("/foo/bar");
scope.$emit("$locationChangeSuccess");
expect(match[0]).toBe("/foo/bar");
expect(match[1]).toEqual({});

location.path("/foo/baz");
scope.$emit("$locationChangeSuccess");
expect(match[0]).toBe("/foo/:param");
expect(match[1]).toEqual({param: 'baz'});
});

it("should execute rewrite rules", function () {
location.path("/foo");
scope.$emit("$locationChangeSuccess");
Expand Down

0 comments on commit 07c046c

Please sign in to comment.