From 1a41bd1ca4229196688d5962c86ad54e461f3c2a Mon Sep 17 00:00:00 2001 From: vsavkin Date: Sun, 7 Aug 2016 20:09:04 -0700 Subject: [PATCH] feature(router): add route.root returning the root of router state --- modules/@angular/router/src/router_state.ts | 4 ++++ modules/@angular/router/test/router_state.spec.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/modules/@angular/router/src/router_state.ts b/modules/@angular/router/src/router_state.ts index d8ae83bfef..e5ff64da21 100644 --- a/modules/@angular/router/src/router_state.ts +++ b/modules/@angular/router/src/router_state.ts @@ -119,6 +119,8 @@ export class ActivatedRoute { get routeConfig(): Route { return this._futureSnapshot.routeConfig; } + get root(): ActivatedRoute { return this._routerState.root; } + get parent(): ActivatedRoute { return this._routerState.parent(this); } get firstChild(): ActivatedRoute { return this._routerState.firstChild(this); } @@ -207,6 +209,8 @@ export class ActivatedRouteSnapshot { get routeConfig(): Route { return this._routeConfig; } + get root(): ActivatedRouteSnapshot { return this._routerState.root; } + get parent(): ActivatedRouteSnapshot { return this._routerState.parent(this); } get firstChild(): ActivatedRouteSnapshot { return this._routerState.firstChild(this); } diff --git a/modules/@angular/router/test/router_state.spec.ts b/modules/@angular/router/test/router_state.spec.ts index 91a7d248eb..c7c4e5fd1d 100644 --- a/modules/@angular/router/test/router_state.spec.ts +++ b/modules/@angular/router/test/router_state.spec.ts @@ -35,6 +35,11 @@ describe('RouterState & Snapshot', () => { }); it('should return root', () => { + const b = state.root.firstChild; + expect(b.root).toBe(state.root); + }); + + it('should return parent', () => { const b = state.root.firstChild; expect(b.parent).toBe(state.root); }); @@ -72,6 +77,11 @@ describe('RouterState & Snapshot', () => { }); it('should return root', () => { + const b = state.root.firstChild; + expect(b.root).toBe(state.root); + }); + + it('should return parent', () => { const b = state.root.firstChild; expect(b.parent).toBe(state.root); });