package.esm2022.src.statemanager.state_manager.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of router Show documentation
Show all versions of router Show documentation
Angular - the routing library
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Location } from '@angular/common';
import { inject, Injectable } from '@angular/core';
import { BeforeActivateRoutes, NavigationCancel, NavigationCancellationCode, NavigationEnd, NavigationError, NavigationSkipped, NavigationStart, RoutesRecognized, } from '../events';
import { ROUTER_CONFIGURATION } from '../router_config';
import { createEmptyState } from '../router_state';
import { UrlHandlingStrategy } from '../url_handling_strategy';
import { UrlSerializer, UrlTree } from '../url_tree';
import * as i0 from "@angular/core";
export class StateManager {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: StateManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: StateManager, providedIn: 'root', useFactory: () => inject(HistoryStateManager) }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: StateManager, decorators: [{
type: Injectable,
args: [{ providedIn: 'root', useFactory: () => inject(HistoryStateManager) }]
}] });
export class HistoryStateManager extends StateManager {
constructor() {
super(...arguments);
this.location = inject(Location);
this.urlSerializer = inject(UrlSerializer);
this.options = inject(ROUTER_CONFIGURATION, { optional: true }) || {};
this.canceledNavigationResolution = this.options.canceledNavigationResolution || 'replace';
this.urlHandlingStrategy = inject(UrlHandlingStrategy);
this.urlUpdateStrategy = this.options.urlUpdateStrategy || 'deferred';
this.currentUrlTree = new UrlTree();
this.rawUrlTree = this.currentUrlTree;
/**
* The id of the currently active page in the router.
* Updated to the transition's target id on a successful navigation.
*
* This is used to track what page the router last activated. When an attempted navigation fails,
* the router can then use this to compute how to restore the state back to the previously active
* page.
*/
this.currentPageId = 0;
this.lastSuccessfulId = -1;
this.routerState = createEmptyState(null);
this.stateMemento = this.createStateMemento();
}
getCurrentUrlTree() {
return this.currentUrlTree;
}
getRawUrlTree() {
return this.rawUrlTree;
}
restoredState() {
return this.location.getState();
}
/**
* The ɵrouterPageId of whatever page is currently active in the browser history. This is
* important for computing the target page id for new navigations because we need to ensure each
* page id in the browser history is 1 more than the previous entry.
*/
get browserPageId() {
if (this.canceledNavigationResolution !== 'computed') {
return this.currentPageId;
}
return this.restoredState()?.ɵrouterPageId ?? this.currentPageId;
}
getRouterState() {
return this.routerState;
}
createStateMemento() {
return {
rawUrlTree: this.rawUrlTree,
currentUrlTree: this.currentUrlTree,
routerState: this.routerState,
};
}
registerNonRouterCurrentEntryChangeListener(listener) {
return this.location.subscribe((event) => {
if (event['type'] === 'popstate') {
listener(event['url'], event.state);
}
});
}
handleRouterEvent(e, currentTransition) {
if (e instanceof NavigationStart) {
this.stateMemento = this.createStateMemento();
}
else if (e instanceof NavigationSkipped) {
this.rawUrlTree = currentTransition.initialUrl;
}
else if (e instanceof RoutesRecognized) {
if (this.urlUpdateStrategy === 'eager') {
if (!currentTransition.extras.skipLocationChange) {
const rawUrl = this.urlHandlingStrategy.merge(currentTransition.finalUrl, currentTransition.initialUrl);
this.setBrowserUrl(currentTransition.targetBrowserUrl ?? rawUrl, currentTransition);
}
}
}
else if (e instanceof BeforeActivateRoutes) {
this.currentUrlTree = currentTransition.finalUrl;
this.rawUrlTree = this.urlHandlingStrategy.merge(currentTransition.finalUrl, currentTransition.initialUrl);
this.routerState = currentTransition.targetRouterState;
if (this.urlUpdateStrategy === 'deferred' && !currentTransition.extras.skipLocationChange) {
this.setBrowserUrl(currentTransition.targetBrowserUrl ?? this.rawUrlTree, currentTransition);
}
}
else if (e instanceof NavigationCancel &&
(e.code === NavigationCancellationCode.GuardRejected ||
e.code === NavigationCancellationCode.NoDataFromResolver)) {
this.restoreHistory(currentTransition);
}
else if (e instanceof NavigationError) {
this.restoreHistory(currentTransition, true);
}
else if (e instanceof NavigationEnd) {
this.lastSuccessfulId = e.id;
this.currentPageId = this.browserPageId;
}
}
setBrowserUrl(url, transition) {
const path = url instanceof UrlTree ? this.urlSerializer.serialize(url) : url;
if (this.location.isCurrentPathEqualTo(path) || !!transition.extras.replaceUrl) {
// replacements do not update the target page
const currentBrowserPageId = this.browserPageId;
const state = {
...transition.extras.state,
...this.generateNgRouterState(transition.id, currentBrowserPageId),
};
this.location.replaceState(path, '', state);
}
else {
const state = {
...transition.extras.state,
...this.generateNgRouterState(transition.id, this.browserPageId + 1),
};
this.location.go(path, '', state);
}
}
/**
* Performs the necessary rollback action to restore the browser URL to the
* state before the transition.
*/
restoreHistory(navigation, restoringFromCaughtError = false) {
if (this.canceledNavigationResolution === 'computed') {
const currentBrowserPageId = this.browserPageId;
const targetPagePosition = this.currentPageId - currentBrowserPageId;
if (targetPagePosition !== 0) {
this.location.historyGo(targetPagePosition);
}
else if (this.currentUrlTree === navigation.finalUrl && targetPagePosition === 0) {
// We got to the activation stage (where currentUrlTree is set to the navigation's
// finalUrl), but we weren't moving anywhere in history (skipLocationChange or replaceUrl).
// We still need to reset the router state back to what it was when the navigation started.
this.resetState(navigation);
this.resetUrlToCurrentUrlTree();
}
else {
// The browser URL and router state was not updated before the navigation cancelled so
// there's no restoration needed.
}
}
else if (this.canceledNavigationResolution === 'replace') {
// TODO(atscott): It seems like we should _always_ reset the state here. It would be a no-op
// for `deferred` navigations that haven't change the internal state yet because guards
// reject. For 'eager' navigations, it seems like we also really should reset the state
// because the navigation was cancelled. Investigate if this can be done by running TGP.
if (restoringFromCaughtError) {
this.resetState(navigation);
}
this.resetUrlToCurrentUrlTree();
}
}
resetState(navigation) {
this.routerState = this.stateMemento.routerState;
this.currentUrlTree = this.stateMemento.currentUrlTree;
// Note here that we use the urlHandlingStrategy to get the reset `rawUrlTree` because it may be
// configured to handle only part of the navigation URL. This means we would only want to reset
// the part of the navigation handled by the Angular router rather than the whole URL. In
// addition, the URLHandlingStrategy may be configured to specifically preserve parts of the URL
// when merging, such as the query params so they are not lost on a refresh.
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, navigation.finalUrl ?? this.rawUrlTree);
}
resetUrlToCurrentUrlTree() {
this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree), '', this.generateNgRouterState(this.lastSuccessfulId, this.currentPageId));
}
generateNgRouterState(navigationId, routerPageId) {
if (this.canceledNavigationResolution === 'computed') {
return { navigationId, ɵrouterPageId: routerPageId };
}
return { navigationId };
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: HistoryStateManager, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: HistoryStateManager, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: HistoryStateManager, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGVfbWFuYWdlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci9zcmMvc3RhdGVtYW5hZ2VyL3N0YXRlX21hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLFFBQVEsRUFBQyxNQUFNLGlCQUFpQixDQUFDO0FBQ3pDLE9BQU8sRUFBQyxNQUFNLEVBQUUsVUFBVSxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBR2pELE9BQU8sRUFDTCxvQkFBb0IsRUFFcEIsZ0JBQWdCLEVBQ2hCLDBCQUEwQixFQUMxQixhQUFhLEVBQ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