-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(router): move around some code to eliminate circular deps
This commit eliminates some circular dependencies by moving around interfaces and type guards.
- Loading branch information
Showing
12 changed files
with
152 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @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 {NavigationCancellationCode} from './events'; | ||
import {NavigationBehaviorOptions} from './models'; | ||
import {isUrlTree, UrlSerializer, UrlTree} from './url_tree'; | ||
|
||
export const NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError'; | ||
|
||
export type NavigationCancelingError = | ||
Error&{[NAVIGATION_CANCELING_ERROR]: true, cancellationCode: NavigationCancellationCode}; | ||
export type RedirectingNavigationCancelingError = NavigationCancelingError&{ | ||
url: UrlTree; | ||
navigationBehaviorOptions?: NavigationBehaviorOptions; | ||
cancellationCode: NavigationCancellationCode.Redirect; | ||
}; | ||
|
||
export function redirectingNavigationError( | ||
urlSerializer: UrlSerializer, redirect: UrlTree): RedirectingNavigationCancelingError { | ||
const {redirectTo, navigationBehaviorOptions} = | ||
isUrlTree(redirect) ? {redirectTo: redirect, navigationBehaviorOptions: undefined} : redirect; | ||
const error = | ||
navigationCancelingError( | ||
ngDevMode && `Redirecting to "${urlSerializer.serialize(redirectTo)}"`, | ||
NavigationCancellationCode.Redirect, redirect) as RedirectingNavigationCancelingError; | ||
error.url = redirectTo; | ||
error.navigationBehaviorOptions = navigationBehaviorOptions; | ||
return error; | ||
} | ||
|
||
export function navigationCancelingError( | ||
message: string|null|false, code: NavigationCancellationCode, redirectUrl?: UrlTree) { | ||
const error = new Error(ngDevMode && 'NavigationCancelingError: ' + (message || '') || '') as | ||
NavigationCancelingError; | ||
error[NAVIGATION_CANCELING_ERROR] = true; | ||
error.cancellationCode = code; | ||
if (redirectUrl) { | ||
(error as RedirectingNavigationCancelingError).url = redirectUrl; | ||
} | ||
return error; | ||
} | ||
|
||
export function isRedirectingNavigationCancelingError( | ||
error: unknown| | ||
RedirectingNavigationCancelingError): error is RedirectingNavigationCancelingError { | ||
return isNavigationCancelingError(error) && isUrlTree((error as any).url); | ||
} | ||
export function isNavigationCancelingError(error: unknown): error is NavigationCancelingError { | ||
return error && (error as any)[NAVIGATION_CANCELING_ERROR]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.