/** * @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.io/license */ import { isUrlTree } from './url_tree'; export const NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError'; export function redirectingNavigationError(urlSerializer, redirect) { const { redirectTo, navigationBehaviorOptions } = isUrlTree(redirect) ? { redirectTo: redirect, navigationBehaviorOptions: undefined } : redirect; const error = navigationCancelingError(ngDevMode && `Redirecting to "${urlSerializer.serialize(redirectTo)}"`, 0 /* NavigationCancellationCode.Redirect */, redirect); error.url = redirectTo; error.navigationBehaviorOptions = navigationBehaviorOptions; return error; } export function navigationCancelingError(message, code, redirectUrl) { const error = new Error('NavigationCancelingError: ' + (message || '')); error[NAVIGATION_CANCELING_ERROR] = true; error.cancellationCode = code; if (redirectUrl) { error.url = redirectUrl; } return error; } export function isRedirectingNavigationCancelingError(error) { return isNavigationCancelingError(error) && isUrlTree(error.url); } export function isNavigationCancelingError(error) { return error && error[NAVIGATION_CANCELING_ERROR]; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF2aWdhdGlvbl9jYW5jZWxpbmdfZXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9yb3V0ZXIvc3JjL25hdmlnYXRpb25fY2FuY2VsaW5nX2Vycm9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUlILE9BQU8sRUFBQyxTQUFTLEVBQXlCLE1BQU0sWUFBWSxDQUFDO0FBRTdELE1BQU0sQ0FBQyxNQUFNLDBCQUEwQixHQUFHLDRCQUE0QixDQUFDO0FBVXZFLE1BQU0sVUFBVSwwQkFBMEIsQ0FDdEMsYUFBNEIsRUFBRSxRQUFpQjtJQUNqRCxNQUFNLEVBQUMsVUFBVSxFQUFFLHlCQUF5QixFQUFDLEdBQ3pDLFNBQ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