package.esm2022.src.utils.navigations.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 { filter, map, take } from 'rxjs/operators';
import { NavigationCancel, NavigationCancellationCode, NavigationEnd, NavigationError, NavigationSkipped, } from '../events';
var NavigationResult;
(function (NavigationResult) {
NavigationResult[NavigationResult["COMPLETE"] = 0] = "COMPLETE";
NavigationResult[NavigationResult["FAILED"] = 1] = "FAILED";
NavigationResult[NavigationResult["REDIRECTING"] = 2] = "REDIRECTING";
})(NavigationResult || (NavigationResult = {}));
/**
* Performs the given action once the router finishes its next/current navigation.
*
* The navigation is considered complete under the following conditions:
* - `NavigationCancel` event emits and the code is not `NavigationCancellationCode.Redirect` or
* `NavigationCancellationCode.SupersededByNewNavigation`. In these cases, the
* redirecting/superseding navigation must finish.
* - `NavigationError`, `NavigationEnd`, or `NavigationSkipped` event emits
*/
export function afterNextNavigation(router, action) {
router.events
.pipe(filter((e) => e instanceof NavigationEnd ||
e instanceof NavigationCancel ||
e instanceof NavigationError ||
e instanceof NavigationSkipped), map((e) => {
if (e instanceof NavigationEnd || e instanceof NavigationSkipped) {
return NavigationResult.COMPLETE;
}
const redirecting = e instanceof NavigationCancel
? e.code === NavigationCancellationCode.Redirect ||
e.code === NavigationCancellationCode.SupersededByNewNavigation
: false;
return redirecting ? NavigationResult.REDIRECTING : NavigationResult.FAILED;
}), filter((result) => result !== NavigationResult.REDIRECTING), take(1))
.subscribe(() => {
action();
});
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF2aWdhdGlvbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9yb3V0ZXIvc3JjL3V0aWxzL25hd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