feature(router): add route.root returning the root of router state

This commit is contained in:
vsavkin 2016-08-07 20:09:04 -07:00 committed by Alex Rickabaugh
parent 5a99393355
commit 1a41bd1ca4
2 changed files with 14 additions and 0 deletions

View File

@ -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); }

View File

@ -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);
});