MCPcopy Create free account
hub / github.com/angular/angular / navigateToSyncWithBrowser

Method navigateToSyncWithBrowser

packages/router/src/router.ts:311–357  ·  view source on GitHub ↗

* Schedules a router navigation to synchronize Router state with the browser state. * * This is done as a response to a popstate event and the initial navigation. These * two scenarios represent times when the browser URL/state has been updated and * the Router needs to respond to ensure

(
    url: string,
    source: NavigationTrigger,
    state: RestoredState | null | undefined,
    extras: NavigationExtras,
    hasUAVisualTransition?: boolean,
  )

Source from the content-addressed store, hash-verified

309 * the Router needs to respond to ensure its internal state matches.
310 */
311 private navigateToSyncWithBrowser(
312 url: string,
313 source: NavigationTrigger,
314 state: RestoredState | null | undefined,
315 extras: NavigationExtras,
316 hasUAVisualTransition?: boolean,
317 ) {
318 // TODO: restoredState should always include the entire state, regardless
319 // of navigationId. This requires a breaking change to update the type on
320 // NavigationStart’s restoredState, which currently requires navigationId
321 // to always be present. The Router used to only restore history state if
322 // a navigationId was present.
323
324 // The stored navigationId is used by the RouterScroller to retrieve the scroll
325 // position for the page.
326 const restoredState = state?.navigationId ? state : null;
327
328 // When `browserUrl` was used during the original navigation, the actual route URL
329 // was stored in history state as `ɵrouterUrl`. Use it for route matching and
330 // preserve the browser URL as the displayed URL.
331 const routerUrl = state?.ɵrouterUrl ?? url;
332 if (state?.ɵrouterUrl) {
333 extras = {...extras, browserUrl: url};
334 }
335
336 // Separate to NavigationStart.restoredState, we must also restore the state to
337 // history.state and generate a new navigationId, since it will be overwritten
338 if (state) {
339 const stateCopy = {...state} as Partial<RestoredState>;
340 delete stateCopy.navigationId;
341 delete stateCopy.ɵrouterPageId;
342 delete stateCopy.ɵrouterUrl;
343 if (Object.keys(stateCopy).length !== 0) {
344 extras.state = stateCopy;
345 }
346 }
347
348 const urlTree = this.parseUrl(routerUrl);
349 this.scheduleNavigation(urlTree, source, restoredState, extras, hasUAVisualTransition).catch(
350 (e) => {
351 if (this.disposed) {
352 return;
353 }
354 this.injector.get(ɵINTERNAL_APPLICATION_ERROR_HANDLER)(e);
355 },
356 );
357 }
358
359 /** The current URL. */
360 get url(): string {

Callers 2

initialNavigationMethod · 0.95

Calls 5

parseUrlMethod · 0.95
scheduleNavigationMethod · 0.95
keysMethod · 0.65
getMethod · 0.65
catchMethod · 0.45

Tested by

no test coverage detected