refactor(router): create pipeable afterPreactivation function (#25740)
PR Close #25740
This commit is contained in:
parent
855ad8804e
commit
5d689469f6
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
|
* found in the LICENSE file at https://angular.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {MonoTypeOperatorFunction} from 'rxjs';
|
||||||
|
import {map, mergeMap} from 'rxjs/operators';
|
||||||
|
|
||||||
|
import {RouterHook} from '../router';
|
||||||
|
import {RouterStateSnapshot} from '../router_state';
|
||||||
|
import {UrlTree} from '../url_tree';
|
||||||
|
|
||||||
|
export function afterPreactivation(
|
||||||
|
hook: RouterHook, navigationId: number, appliedUrlTree: UrlTree, rawUrlTree: UrlTree,
|
||||||
|
skipLocationChange: boolean, replaceUrl: boolean):
|
||||||
|
MonoTypeOperatorFunction<{appliedUrl: UrlTree, snapshot: RouterStateSnapshot}> {
|
||||||
|
return function(source) {
|
||||||
|
return source.pipe(mergeMap(
|
||||||
|
p => hook(
|
||||||
|
p.snapshot,
|
||||||
|
{
|
||||||
|
navigationId, appliedUrlTree, rawUrlTree, skipLocationChange, replaceUrl,
|
||||||
|
})
|
||||||
|
.pipe(map(() => p))));
|
||||||
|
};
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ import {DefaultUrlHandlingStrategy, UrlHandlingStrategy} from './url_handling_st
|
||||||
import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tree';
|
import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tree';
|
||||||
import {forEach} from './utils/collection';
|
import {forEach} from './utils/collection';
|
||||||
import {TreeNode, nodeChildrenAsMap} from './utils/tree';
|
import {TreeNode, nodeChildrenAsMap} from './utils/tree';
|
||||||
|
import { afterPreactivation } from './operators/after_preactivation';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -769,17 +770,13 @@ export class Router {
|
||||||
of (p)
|
of (p)
|
||||||
));
|
));
|
||||||
|
|
||||||
const preactivationDone$ =
|
const preactivationDone$: Observable<NavStreamValue> =
|
||||||
preactivationResolveData$.pipe(mergeMap((p): Observable<NavStreamValue> => {
|
preactivationResolveData$.pipe(mergeMap(p =>
|
||||||
if (typeof p === 'boolean' || this.navigationId !== id) return of (false);
|
typeof p === 'boolean' || this.navigationId !== id ? of (false) :
|
||||||
return this.hooks
|
of (p).pipe(
|
||||||
.afterPreactivation(p.snapshot, {
|
afterPreactivation(this.hooks.afterPreactivation, id, url, rawUrl, skipLocationChange, replaceUrl),
|
||||||
navigationId: id,
|
map(() => p))
|
||||||
appliedUrlTree: url,
|
));
|
||||||
rawUrlTree: rawUrl, skipLocationChange, replaceUrl,
|
|
||||||
})
|
|
||||||
.pipe(map(() => p));
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
// create router state
|
// create router state
|
||||||
|
|
Loading…
Reference in New Issue