@@ -14,7 +14,7 @@ import {catchError, defaultIfEmpty, filter, finalize, map, switchMap, take, tap}
1414import { createRouterState } from './create_router_state' ;
1515import { createUrlTree } from './create_url_tree' ;
1616import { RuntimeErrorCode } from './errors' ;
17- import { Event , GuardsCheckEnd , GuardsCheckStart , NavigationCancel , NavigationEnd , NavigationError , NavigationStart , NavigationTrigger , ResolveEnd , ResolveStart , RouteConfigLoadEnd , RouteConfigLoadStart , RoutesRecognized } from './events' ;
17+ import { Event , GuardsCheckEnd , GuardsCheckStart , NavigationCancel , NavigationCancellationCode , NavigationEnd , NavigationError , NavigationStart , NavigationTrigger , ResolveEnd , ResolveStart , RouteConfigLoadEnd , RouteConfigLoadStart , RoutesRecognized } from './events' ;
1818import { QueryParamsHandling , Route , Routes } from './models' ;
1919import { activateRoutes } from './operators/activate_routes' ;
2020import { applyRedirects } from './operators/apply_redirects' ;
@@ -411,8 +411,7 @@ export class Router {
411411 private disposed = false ;
412412
413413 private locationSubscription ?: SubscriptionLike ;
414- /** @internal */
415- navigationId : number = 0 ;
414+ private navigationId : number = 0 ;
416415
417416 /**
418417 * The id of the currently active page in the router.
@@ -779,7 +778,8 @@ export class Router {
779778 filter ( t => {
780779 if ( ! t . guardsResult ) {
781780 this . restoreHistory ( t ) ;
782- this . cancelNavigationTransition ( t , '' ) ;
781+ this . cancelNavigationTransition (
782+ t , '' , NavigationCancellationCode . GuardRejected ) ;
783783 return false ;
784784 }
785785 return true ;
@@ -807,7 +807,10 @@ export class Router {
807807 this . restoreHistory ( t ) ;
808808 this . cancelNavigationTransition (
809809 t ,
810- `At least one route resolver didn't emit any value.` ) ;
810+ NG_DEV_MODE ?
811+ `At least one route resolver didn't emit any value.` :
812+ '' ,
813+ NavigationCancellationCode . NoDataFromResolver ) ;
811814 }
812815 }
813816 } ) ,
@@ -896,9 +899,13 @@ export class Router {
896899 * event is fired when a navigation gets cancelled but not caught by other
897900 * means. */
898901 if ( ! completed && ! errored ) {
899- const cancelationReason = `Navigation ID ${
900- t . id } is not equal to the current navigation id ${ this . navigationId } `;
901- this . cancelNavigationTransition ( t , cancelationReason ) ;
902+ const cancelationReason = NG_DEV_MODE ?
903+ `Navigation ID ${ t . id } is not equal to the current navigation id ${
904+ this . navigationId } ` :
905+ '' ;
906+ this . cancelNavigationTransition (
907+ t , cancelationReason ,
908+ NavigationCancellationCode . SupersededByNewNavigation ) ;
902909 }
903910 // Only clear current navigation if it is still set to the one that
904911 // finalized.
@@ -933,7 +940,8 @@ export class Router {
933940 this . restoreHistory ( t , true ) ;
934941 }
935942 const navCancel = new NavigationCancel (
936- t . id , this . serializeUrl ( t . extractedUrl ) , e . message ) ;
943+ t . id , this . serializeUrl ( t . extractedUrl ) , e . message ,
944+ NavigationCancellationCode . Redirect ) ;
937945 eventsSubject . next ( navCancel ) ;
938946
939947 // When redirecting, we need to delay resolving the navigation
@@ -1460,8 +1468,9 @@ export class Router {
14601468 this . generateNgRouterState ( this . lastSuccessfulId , this . currentPageId ) ) ;
14611469 }
14621470
1463- private cancelNavigationTransition ( t : NavigationTransition , reason : string ) {
1464- const navCancel = new NavigationCancel ( t . id , this . serializeUrl ( t . extractedUrl ) , reason ) ;
1471+ private cancelNavigationTransition (
1472+ t : NavigationTransition , reason : string , code : NavigationCancellationCode ) {
1473+ const navCancel = new NavigationCancel ( t . id , this . serializeUrl ( t . extractedUrl ) , reason , code ) ;
14651474 this . triggerEvent ( navCancel ) ;
14661475 t . resolve ( false ) ;
14671476 }
0 commit comments