()
| 93 | * button or the escape key (again, on desktop). |
| 94 | */ |
| 95 | const initializeNavigationAdapter = () => { |
| 96 | const router = inject(Router); |
| 97 | const window = inject(WINDOW); |
| 98 | const navigation = window.navigation; |
| 99 | if (!navigation || !inject(DOCUMENT).startViewTransition) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | let intercept = false; |
| 104 | let clearNavigation: (() => void) | undefined; |
| 105 | navigation.addEventListener('navigateerror', async () => { |
| 106 | if (!clearNavigation) { |
| 107 | return; |
| 108 | } |
| 109 | clearNavigation = undefined; |
| 110 | router.currentNavigation()?.abort(); |
| 111 | }); |
| 112 | navigation.addEventListener('navigate', (navigateEvent) => { |
| 113 | if (!intercept) { |
| 114 | return; |
| 115 | } |
| 116 | navigateEvent.intercept({ |
| 117 | handler: () => |
| 118 | new Promise<void>((_, reject) => { |
| 119 | clearNavigation = () => { |
| 120 | clearNavigation = undefined; |
| 121 | reject(); |
| 122 | }; |
| 123 | }), |
| 124 | }); |
| 125 | }); |
| 126 | |
| 127 | merge(transitionCreated.pipe(map(() => 'viewtransition')), router.events).subscribe((e) => { |
| 128 | // Skip this for popstate/traversals that are already committed. |
| 129 | // The rollback is problematic so we only do it for navigations that |
| 130 | // defer the actual update (pushState) on the browser. |
| 131 | const currentNavigation = router.currentNavigation(); |
| 132 | if (currentNavigation?.trigger === 'popstate' || currentNavigation?.extras.replaceUrl) { |
| 133 | return; |
| 134 | } |
| 135 | if (e instanceof NavigationStart) { |
| 136 | intercept = true; |
| 137 | window.history.replaceState(window.history.state, '', window.location.href); |
| 138 | intercept = false; |
| 139 | } else if ( |
| 140 | // viewtransition happens before NavigateEnd |
| 141 | e === 'viewtransition' || |
| 142 | e instanceof NavigationCancel || |
| 143 | e instanceof NavigationError |
| 144 | ) { |
| 145 | clearNavigation?.(); |
| 146 | } |
| 147 | }); |
| 148 | }; |
no test coverage detected
searching dependent graphs…