From 20c463e97cfd32266172bbdc5016a71621f12704 Mon Sep 17 00:00:00 2001 From: Jason Aden Date: Wed, 30 May 2018 11:20:48 -0700 Subject: [PATCH] feat(router): add navigation execution context info to activation hooks (#24204) This change adds to internal API hooks (undocumented API) for `before/afterPreactivation`. The immediate need for this API is to allow applications to build support for marshalling navigation between a web worker and the main application. Fixes #24202 PR Close #24204 --- packages/router/src/router.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index 1cf291a4b9..bdee78a836 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -177,12 +177,24 @@ type NavigationParams = { /** * @internal */ -export type RouterHook = (snapshot: RouterStateSnapshot) => Observable; +export type RouterHook = (snapshot: RouterStateSnapshot, runExtras: { + appliedUrlTree: UrlTree, + rawUrlTree: UrlTree, + skipLocationChange: boolean, + replaceUrl: boolean, + navigationId: number +}) => Observable; /** * @internal */ -function defaultRouterHook(snapshot: RouterStateSnapshot): Observable { +function defaultRouterHook(snapshot: RouterStateSnapshot, runExtras: { + appliedUrlTree: UrlTree, + rawUrlTree: UrlTree, + skipLocationChange: boolean, + replaceUrl: boolean, + navigationId: number +}): Observable { return of (null) as any; } @@ -645,7 +657,13 @@ export class Router { const beforePreactivationDone$ = urlAndSnapshot$.pipe(mergeMap((p): Observable => { if (typeof p === 'boolean') return of (p); - return this.hooks.beforePreactivation(p.snapshot).pipe(map(() => p)); + return this.hooks + .beforePreactivation(p.snapshot, { + navigationId: id, + appliedUrlTree: url, + rawUrlTree: rawUrl, skipLocationChange, replaceUrl, + }) + .pipe(map(() => p)); })); // run preactivation: guards and data resolvers @@ -698,7 +716,13 @@ export class Router { const preactivationDone$ = preactivationResolveData$.pipe(mergeMap((p): Observable => { if (typeof p === 'boolean' || this.navigationId !== id) return of (false); - return this.hooks.afterPreactivation(p.snapshot).pipe(map(() => p)); + return this.hooks + .afterPreactivation(p.snapshot, { + navigationId: id, + appliedUrlTree: url, + rawUrlTree: rawUrl, skipLocationChange, replaceUrl, + }) + .pipe(map(() => p)); }));