(router: {events: Observable<Event>}, action: () => void)
| 34 | * - `NavigationError`, `NavigationEnd`, or `NavigationSkipped` event emits |
| 35 | */ |
| 36 | export function afterNextNavigation(router: {events: Observable<Event>}, action: () => void): void { |
| 37 | router.events |
| 38 | .pipe( |
| 39 | filter( |
| 40 | (e): e is NavigationEnd | NavigationCancel | NavigationError | NavigationSkipped => |
| 41 | e instanceof NavigationEnd || |
| 42 | e instanceof NavigationCancel || |
| 43 | e instanceof NavigationError || |
| 44 | e instanceof NavigationSkipped, |
| 45 | ), |
| 46 | map((e) => { |
| 47 | if (e instanceof NavigationEnd || e instanceof NavigationSkipped) { |
| 48 | return NavigationResult.COMPLETE; |
| 49 | } |
| 50 | const redirecting = |
| 51 | e instanceof NavigationCancel |
| 52 | ? e.code === NavigationCancellationCode.Redirect || |
| 53 | e.code === NavigationCancellationCode.SupersededByNewNavigation |
| 54 | : false; |
| 55 | return redirecting ? NavigationResult.REDIRECTING : NavigationResult.FAILED; |
| 56 | }), |
| 57 | filter( |
| 58 | (result): result is NavigationResult.COMPLETE | NavigationResult.FAILED => |
| 59 | result !== NavigationResult.REDIRECTING, |
| 60 | ), |
| 61 | take(1), |
| 62 | ) |
| 63 | .subscribe(() => { |
| 64 | action(); |
| 65 | }); |
| 66 | } |
searching dependent graphs…