From 1681e4f57f4c4fa45a556502df0533131c2d64b4 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 5 Oct 2016 14:43:26 -0700 Subject: [PATCH] fix(router): parent resolve should complete before merging resolved data Closes #12032 --- modules/@angular/router/src/router.ts | 3 ++- modules/@angular/router/test/router.spec.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index 462ae20108..38c6cd917e 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -13,6 +13,7 @@ import {Subject} from 'rxjs/Subject'; import {Subscription} from 'rxjs/Subscription'; import {from} from 'rxjs/observable/from'; import {of } from 'rxjs/observable/of'; +import {concatMap} from 'rxjs/operator/concatMap'; import {every} from 'rxjs/operator/every'; import {map} from 'rxjs/operator/map'; import {mergeAll} from 'rxjs/operator/mergeAll'; @@ -692,7 +693,7 @@ export class PreActivation { resolveData(): Observable { if (this.checks.length === 0) return of (null); const checks$ = from(this.checks); - const runningChecks$ = mergeMap.call(checks$, (s: any) => { + const runningChecks$ = concatMap.call(checks$, (s: any) => { if (s instanceof CanActivate) { return this.runResolve(s.route); } else { diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index 007e6c9b7a..3722fd5e1d 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -48,6 +48,23 @@ describe('Router', () => { }); }); + it('should wait for the parent resolve to complete', () => { + const parentResolve = new InheritedResolve(InheritedResolve.empty, {data: 'resolver'}); + const childResolve = new InheritedResolve(parentResolve, {}); + + const parent = createActivatedRouteSnapshot('a', {resolve: parentResolve}); + const child = createActivatedRouteSnapshot('b', {resolve: childResolve}); + + const s = new RouterStateSnapshot( + 'url', new TreeNode(empty.root, [new TreeNode(parent, [new TreeNode(child, [])])])); + + const inj = {get: (token: any) => () => Promise.resolve(`${token}_value`)}; + + checkResolveData(s, empty, inj, () => { + expect(s.root.firstChild.firstChild.data).toEqual({data: 'resolver_value'}); + }); + }); + it('should copy over data when creating a snapshot', () => { const r1 = new InheritedResolve(InheritedResolve.empty, {data: 'resolver1'}); const r2 = new InheritedResolve(InheritedResolve.empty, {data: 'resolver2'});