parent
							
								
									c574e6808f
								
							
						
					
					
						commit
						67c80fbb5e
					
				| @ -9,6 +9,7 @@ import {RouterOutlet} from './directives/router_outlet'; | |||||||
| import {getCanActivateHook} from './lifecycle/route_lifecycle_reflector'; | import {getCanActivateHook} from './lifecycle/route_lifecycle_reflector'; | ||||||
| import {RouteDefinition} from './route_config/route_config_impl'; | import {RouteDefinition} from './route_config/route_config_impl'; | ||||||
| import {Injectable, Inject} from '@angular/core'; | import {Injectable, Inject} from '@angular/core'; | ||||||
|  | import {DefaultInstruction} from "./instruction"; | ||||||
| 
 | 
 | ||||||
| let _resolveToTrue = PromiseWrapper.resolve(true); | let _resolveToTrue = PromiseWrapper.resolve(true); | ||||||
| let _resolveToFalse = PromiseWrapper.resolve(false); | let _resolveToFalse = PromiseWrapper.resolve(false); | ||||||
| @ -131,8 +132,9 @@ export class Router { | |||||||
|    */ |    */ | ||||||
|   isRouteActive(instruction: Instruction): boolean { |   isRouteActive(instruction: Instruction): boolean { | ||||||
|     var router: Router = this; |     var router: Router = this; | ||||||
|  |     var currentInstruction = this.currentInstruction; | ||||||
| 
 | 
 | ||||||
|     if (isBlank(this.currentInstruction)) { |     if (isBlank(currentInstruction)) { | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -142,22 +144,28 @@ export class Router { | |||||||
|       instruction = instruction.child; |       instruction = instruction.child; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (isBlank(instruction.component) || isBlank(this.currentInstruction.component) || |     let reason = true; | ||||||
|         this.currentInstruction.component.routeName != instruction.component.routeName) { |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     let paramEquals = true; |     // check the instructions in depth
 | ||||||
|  |     do { | ||||||
|  |       if (isBlank(instruction.component) || isBlank(currentInstruction.component) || | ||||||
|  |           currentInstruction.component.routeName != instruction.component.routeName) { | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |       if (isPresent(instruction.component.params)) { | ||||||
|  |         StringMapWrapper.forEach(instruction.component.params, (value, key) => { | ||||||
|  |           if (currentInstruction.component.params[key] !== value) { | ||||||
|  |             reason = false; | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |       currentInstruction = currentInstruction.child; | ||||||
|  |       instruction = instruction.child; | ||||||
|  |     } while (isPresent(currentInstruction) && isPresent(instruction) && | ||||||
|  |              !(instruction instanceof DefaultInstruction) && reason); | ||||||
| 
 | 
 | ||||||
|     if (isPresent(this.currentInstruction.component.params)) { |     // ignore DefaultInstruction
 | ||||||
|       StringMapWrapper.forEach(instruction.component.params, (value, key) => { |     return reason && (isBlank(instruction) || instruction instanceof DefaultInstruction); | ||||||
|         if (this.currentInstruction.component.params[key] !== value) { |  | ||||||
|           paramEquals = false; |  | ||||||
|         } |  | ||||||
|       }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return paramEquals; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -295,6 +295,51 @@ export function main() { | |||||||
|                  router.navigateByUrl('/child-with-grandchild/grandchild?extra=0'); |                  router.navigateByUrl('/child-with-grandchild/grandchild?extra=0'); | ||||||
|                }); |                }); | ||||||
|          })); |          })); | ||||||
|  | 
 | ||||||
|  |       it('should not be added to links in other child routes', | ||||||
|  |          inject([AsyncTestCompleter], (async) => { | ||||||
|  |            router.config([ | ||||||
|  |                    new Route({path: '/child', component: HelloCmp, name: 'Child'}), | ||||||
|  |                    new Route({ | ||||||
|  |                      path: '/child-with-grandchild/...', | ||||||
|  |                      component: ParentCmp, | ||||||
|  |                      name: 'ChildWithGrandchild' | ||||||
|  |                    }), | ||||||
|  |                    new Route({ | ||||||
|  |                      path: '/child-with-other-grandchild/...', | ||||||
|  |                      component: ParentCmp, | ||||||
|  |                      name: 'ChildWithOtherGrandchild' | ||||||
|  |                    }) | ||||||
|  |                  ]) | ||||||
|  |                .then((_) => compile(`<a [routerLink]="['./Child']" class="child-link">Child</a>
 | ||||||
|  |                     <a [routerLink]="['./ChildWithGrandchild/Grandchild']" class="child-with-grandchild-link">Better Child</a> | ||||||
|  |                     <a [routerLink]="['./ChildWithOtherGrandchild/Grandchild']" class="child-with-other-grandchild-link">Better Child</a> | ||||||
|  |                     <router-outlet></router-outlet>`)) | ||||||
|  |                .then((_) => { | ||||||
|  |                  var element = fixture.debugElement.nativeElement; | ||||||
|  | 
 | ||||||
|  |                  fixture.detectChanges(); | ||||||
|  | 
 | ||||||
|  |                  var link1 = getDOM().querySelector(element, '.child-link'); | ||||||
|  |                  var link2 = getDOM().querySelector(element, '.child-with-grandchild-link'); | ||||||
|  |                  var link3 = getDOM().querySelector(element, '.child-with-other-grandchild-link'); | ||||||
|  | 
 | ||||||
|  |                  expect(link1).not.toHaveCssClass('router-link-active'); | ||||||
|  |                  expect(link2).not.toHaveCssClass('router-link-active'); | ||||||
|  |                  expect(link3).not.toHaveCssClass('router-link-active'); | ||||||
|  | 
 | ||||||
|  |                  router.subscribe((_) => { | ||||||
|  |                    fixture.detectChanges(); | ||||||
|  | 
 | ||||||
|  |                    expect(link1).not.toHaveCssClass('router-link-active'); | ||||||
|  |                    expect(link2).toHaveCssClass('router-link-active'); | ||||||
|  |                    expect(link3).not.toHaveCssClass('router-link-active'); | ||||||
|  | 
 | ||||||
|  |                    async.done(); | ||||||
|  |                  }); | ||||||
|  |                  router.navigateByUrl('/child-with-grandchild/grandchild?extra=0'); | ||||||
|  |                }); | ||||||
|  |          })); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     describe('when clicked', () => { |     describe('when clicked', () => { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user