We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1f781c8 commit b5c57c8Copy full SHA for b5c57c8
src/urlRouter.js
@@ -303,6 +303,12 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
303
return listener;
304
}
305
306
+ rules.sort(function(ruleA, ruleB) {
307
+ var aLength = ruleA.prefix ? ruleA.prefix.length : 0;
308
+ var bLength = ruleB.prefix ? ruleB.prefix.length : 0;
309
+ return bLength - aLength;
310
+ });
311
+
312
if (!interceptDeferred) listen();
313
314
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