We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5910337 + b5c57c8 commit 07c046cCopy full SHA for 07c046c
src/urlRouter.js
@@ -305,6 +305,12 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
305
return listener;
306
}
307
308
+ rules.sort(function(ruleA, ruleB) {
309
+ var aLength = ruleA.prefix ? ruleA.prefix.length : 0;
310
+ var bLength = ruleB.prefix ? ruleB.prefix.length : 0;
311
+ return bLength - aLength;
312
+ });
313
+
314
if (!interceptDeferred) listen();
315
316
return {
test/urlRouterSpec.js
@@ -55,6 +55,8 @@ describe("UrlRouter", function () {
55
return path.replace('baz', 'b4z');
56
}).when('/foo/:param', function($match) {
57
match = ['/foo/:param', $match];
58
+ }).when('/foo/bar', function($match) {
59
+ match = ['/foo/bar', $match];
60
}).when('/bar', function($match) {
61
match = ['/bar', $match];
62
});
@@ -71,6 +73,18 @@ describe("UrlRouter", function () {
71
73
72
74
75
76
+ it("should handle more specified url first", function() {
77
+ location.path("/foo/bar");
78
+ scope.$emit("$locationChangeSuccess");
79
+ expect(match[0]).toBe("/foo/bar");
80
+ expect(match[1]).toEqual({});
81
82
+ location.path("/foo/baz");
83
84
+ expect(match[0]).toBe("/foo/:param");
85
+ expect(match[1]).toEqual({param: 'baz'});
86
87
88
it("should execute rewrite rules", function () {
89
location.path("/foo");
90
scope.$emit("$locationChangeSuccess");
0 commit comments