MCPcopy Index your code
hub / github.com/angular/angular / initializeNavigationAdapter

Function initializeNavigationAdapter

adev/src/app/routing/router_providers.ts:95–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93 * button or the escape key (again, on desktop).
94 */
95const 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};

Callers 1

Calls 8

injectFunction · 0.90
rejectFunction · 0.85
mergeFunction · 0.85
addEventListenerMethod · 0.65
abortMethod · 0.65
interceptMethod · 0.65
subscribeMethod · 0.65
replaceStateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…