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

Method navigateToSyncWithBrowser

packages/router/src/router.ts:312–358  ·  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

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