File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -420,7 +420,15 @@ function $RouteProvider(){
420
420
if ( ! match && ( params = matcher ( $location . path ( ) , path ) ) ) {
421
421
match = inherit ( route , {
422
422
params : extend ( { } , $location . search ( ) , params ) ,
423
- pathParams : params } ) ;
423
+ pathParams : params
424
+ } ) ;
425
+ if ( ( route . templateUrl ) && ( / : / . test ( route . templateUrl ) ) ) {
426
+ match . templateUrl = interpolate ( route . templateUrl , params ) ;
427
+ }
428
+ //remove cached template if params were substituted (rely on browser cache)
429
+ if ( match . templateUrl != route . templateUrl ) {
430
+ match . template = undefined ;
431
+ }
424
432
match . $route = route ;
425
433
}
426
434
} ) ;
Original file line number Diff line number Diff line change @@ -318,6 +318,33 @@ describe('$route', function() {
318
318
} ) ;
319
319
} ) ;
320
320
321
+ it ( 'should interpolate parameters into the url of fetched templates' , function ( ) {
322
+ module ( function ( $routeProvider ) {
323
+ $routeProvider .
324
+ when ( '/foo/:rparam' , { templateUrl :':rparam.html' } ) ;
325
+ } ) ;
326
+
327
+ inject ( function ( $route , $httpBackend , $location , $rootScope ) {
328
+ var log = '' ;
329
+ $rootScope . $on ( '$routeChangeStart' , function ( e , next ) { log += '$before(' + next . templateUrl + ');' } ) ;
330
+ $rootScope . $on ( '$routeChangeSuccess' , function ( e , next ) { log += '$after(' + next . templateUrl + ');' } ) ;
331
+
332
+ $httpBackend . expectGET ( 'r1.html' ) . respond ( 'R1' ) ;
333
+ $httpBackend . expectGET ( 'r2.html' ) . respond ( 'R2' ) ;
334
+
335
+ $location . path ( '/foo/r1' ) ;
336
+ $rootScope . $digest ( ) ;
337
+ expect ( log ) . toBe ( '$before(r1.html);' ) ;
338
+
339
+ $location . path ( '/foo/r2' ) ;
340
+ $rootScope . $digest ( ) ;
341
+ expect ( log ) . toBe ( '$before(r1.html);$before(r2.html);' ) ;
342
+
343
+ $httpBackend . flush ( ) ;
344
+ expect ( log ) . toBe ( '$before(r1.html);$before(r2.html);$after(r2.html);' ) ;
345
+ expect ( log ) . not . toContain ( '$after(r1.html);' ) ;
346
+ } ) ;
347
+ } ) ;
321
348
322
349
it ( 'should not update $routeParams until $routeChangeSuccess' , function ( ) {
323
350
module ( function ( $routeProvider ) {
You can’t perform that action at this time.
0 commit comments