@@ -36,6 +36,15 @@ function $RouteProvider(){
36
36
var key = scopeKey ( scope ) ;
37
37
delete scopedRoutes [ key ] ;
38
38
}
39
+
40
+ function scoped ( scope ) {
41
+ var key = scopeKey ( scope ) ;
42
+ if ( key in scopedRoutes )
43
+ return scopedRoutes [ key ] ;
44
+ else {
45
+ return scoped ( scope . $parent ) ;
46
+ }
47
+ }
39
48
40
49
// the root routes have null scope
41
50
addScope ( null ) ;
@@ -98,23 +107,28 @@ function $RouteProvider(){
98
107
* @description
99
108
* Adds a new route definition to the `$route` service.
100
109
*/
110
+ var trailingRegex = / ^ .* ( \. \. \. | \* ) $ / g;
101
111
function when ( scope , path , route , opts ) {
102
112
113
+ if ( this . base && isString ( path ) && path [ 0 ] !== '/' ) {
114
+ path = this . base + path ;
115
+ }
116
+
103
117
pushRoute ( scope , extend (
104
- { reloadOnSearch : true , reloadOnParams : true } ,
118
+ { reloadOnSearch : true } ,
105
119
route ,
106
- path && pathRegExp ( path , extend ( options , opts ) )
120
+ path && pathRegExp ( path , extend ( { } , options , opts ) )
107
121
) ) ;
108
122
109
123
// create redirection for trailing slashes
110
- if ( path ) {
111
- var redirectPath = ( path [ path . length - 1 ] == '/' )
124
+ if ( path && ! trailingRegex . exec ( path ) ) {
125
+ var redirectPath = ( path [ path . length - 1 ] === '/' )
112
126
? path . substr ( 0 , path . length - 1 )
113
127
: path + '/' ;
114
128
115
129
pushRoute ( scope , extend (
116
130
{ redirectTo : path } ,
117
- pathRegExp ( redirectPath , extend ( options , opts ) )
131
+ pathRegExp ( redirectPath , extend ( { } , options , opts ) )
118
132
) ) ;
119
133
}
120
134
@@ -137,7 +151,6 @@ function $RouteProvider(){
137
151
138
152
path = path
139
153
. replace ( / ( [ \\ \( \) \^ \$ ] ) / g, "\\$1" )
140
- . replace ( / \. \. \. $ / g, opts . noEllipsis ? '' : '(?:.*)' )
141
154
. concat ( strict ? '' : '/?' )
142
155
. replace ( / \/ \( / g, '(?:/' )
143
156
. replace ( / ( \/ ) ? ( \. ) ? : ( \w + ) (?: ( \( .* ?\) ) ) ? ( \? ) ? ( \* ) ? / g, function ( _ , slash , format , key , capture , optional , star ) {
@@ -152,9 +165,13 @@ function $RouteProvider(){
152
165
+ ( star ? '(/*)?' : '' ) ;
153
166
} )
154
167
. replace ( / ( [ \/ . ] ) / g, '\\$1' )
155
- . replace ( / \* / g, '(.*)' ) ;
168
+ . replace ( / \* / g, '(.*)' )
169
+ . replace ( / \\ .\\ .\\ .$ / g, function ( a , b ) {
170
+ ret . ellipsis = true ;
171
+ return ''
172
+ } ) ;
156
173
157
- ret . regexp = new RegExp ( '^' + path + '$' , sensitive ? '' : 'i' )
174
+ ret . regexp = new RegExp ( '^' + path + ( ret . ellipsis ? '' : '$' ) , sensitive ? '' : 'i' ) ;
158
175
return ret
159
176
}
160
177
@@ -175,7 +192,7 @@ function $RouteProvider(){
175
192
routes = scopedRoutes [ key ] . routes ;
176
193
177
194
routes [ null ] = extend (
178
- { reloadOnSearch : true , reloadOnParams : true } ,
195
+ { reloadOnSearch : true } ,
179
196
params ) ;
180
197
return this ;
181
198
}
@@ -199,26 +216,6 @@ function $RouteProvider(){
199
216
}
200
217
201
218
202
-
203
- /*
204
- * @ngdoc method
205
- * @name ng.$routeProvider#options
206
- * @methodOf ng$routeProvider
207
- *
208
- * @description
209
- * Options fore route matching.
210
- * - `sensitive` enable case-sensitive routes
211
- * - `strict` disable strict matching for trailing slashes
212
- */
213
-
214
- this . options = function ( opts ) {
215
- extend ( options , opts ) ;
216
- return this ;
217
- }
218
-
219
-
220
-
221
-
222
219
this . $get = [ '$rootScope' , '$location' , '$routeParams' , '$q' , '$injector' , '$http' , '$templateCache' ,
223
220
function ( $rootScope , $location , $routeParams , $q , $injector , $http , $templateCache ) {
224
221
@@ -464,20 +461,14 @@ function $RouteProvider(){
464
461
} ) ;
465
462
466
463
var ret = { } ;
464
+ ret . base = basePath ( scope . $parent ) ;
467
465
ret . when = bind ( ret , when , scope ) ;
468
466
ret . otherwise = bind ( ret , otherwise , scope ) ;
469
467
ret . updateRoute = bind ( null , updateRoute , scope ) ;
470
468
return ret ;
471
469
} ,
472
470
473
- scoped : function ( scope ) {
474
- var key = scopeKey ( scope ) ;
475
- if ( key in scopedRoutes )
476
- return scopedRoutes [ key ] ;
477
- else {
478
- return $route . scoped ( scope . $parent ) ;
479
- }
480
- }
471
+ scoped : scoped
481
472
} ;
482
473
483
474
$route . __defineGetter__ ( 'current' , function ( ) {
@@ -491,6 +482,12 @@ function $RouteProvider(){
491
482
return $route ;
492
483
493
484
/////////////////////////////////////////////////////
485
+
486
+ function basePath ( scope ) {
487
+ var current = $route . scoped ( scope ) . current ;
488
+ if ( ! current ) return ;
489
+ return current . base ;
490
+ }
494
491
495
492
// http://github.com/visionmedia/express
496
493
function switchRouteMatcher ( on , route ) {
@@ -499,9 +496,14 @@ function $RouteProvider(){
499
496
500
497
if ( ! route . regexp ) return null ;
501
498
499
+
500
+
502
501
var m = route . regexp . exec ( on ) ;
503
502
if ( ! m ) return null ;
504
503
504
+ if ( route . ellipsis )
505
+ route . base = m [ 0 ] ;
506
+
505
507
var N = 0 ;
506
508
for ( var i = 1 , len = m . length ; i < len ; ++ i ) {
507
509
var key = keys [ i - 1 ] ;
@@ -526,8 +528,9 @@ function $RouteProvider(){
526
528
last = route . current ;
527
529
528
530
if ( next && last && next . $route === last . $route &&
529
- ( ! next . reloadOnParams || equals ( next . pathParams , last . pathParams ) && ! next . reloadOnSearch ) &&
530
- ! forceReload ) {
531
+ equals ( next . pathParams , last . pathParams ) &&
532
+ ( ! ( ! equals ( next . params , last . params ) && next . reloadOnSearch ) ) &&
533
+ ! forceReload ) {
531
534
last . params = next . params ;
532
535
if ( ! scope )
533
536
copy ( last . params , $routeParams ) ;
@@ -605,6 +608,7 @@ function $RouteProvider(){
605
608
// Match a route
606
609
var routes = $route . scoped ( scope ) . routes ,
607
610
params , match ;
611
+
608
612
forEach ( routes , function ( route , path ) {
609
613
if ( ! match && ( params = matcher ( $location . path ( ) , route ) ) ) {
610
614
match = inherit ( route , {
0 commit comments