Resets the URL to what it was before the navigation that caused an error. No new navigation is triggered.
'deferred'
(the default) updates the browser URL after successful navigation.'eager'
updates the browser URL at the beginning of navigation. Updating the URL early allows you to handle a failure of navigation by showing an error message with the URL that failed.
- What is the URL after each of the
NavigationCancellationCode
reasons?
Should we add a way to emit events to the router store?
NavigationStart
RoutesRecognized
- Route guards and route resolvers
- Route activated or the router state is rolled back to match the previous route
NavigationEnd
orNavigationCancel
orNavigationError
NavigationSkipped
NavigationCancel#code
:
NavigationCancellationCode.GuardRejected
: A navigation failed because a guard returnedfalse
.NavigationCancellationCode.NoDataFromResolver
: A navigation failed because one of the resolvers completed without emitting a value.NavigationCancellationCode.Redirect
: A navigation failed because a guard returned aUrlTree
to redirect.NavigationCancellationCode.SupersededByNewNavigation
: A navigation failed because a more recent navigation started.NavigationCancel { id: 3, url: "/company", reason: "Navigation ID 3 is not equal to the current navigation id 4" }
- Invalid route path
NavigationError(id: 3, url: '/an-invalid/path', error: Error: Cannot match any routes. URL Segment: 'an-invalid/path')
- Route resolver throws
- Route matcher throws
- Routed component throws in constructor (or a lifecycle hook?)
- Lazy route chunk file is not found (bundles updated and the user needs to refresh)
RouterTestingModule.withRoutes([ { path: 'stale-chunk', loadChildren: () => Promise.reject({ name: 'ChunkLoadError', message: 'ChunkLoadError' }), // or () => { throw { name: 'ChunkLoadError', message: 'ChunkLoadError' }; } }, ]),
location
change to unsupported URL. TheUrlHandlingStrategy
cannot process the current or the target URL.onSameUrlNavigation
is set toignore
(the default) and the target URL is the same as the current URL.
the default
RouterRequestAction
RouterNavigationAction
- Route guards and route resolvers
- Route activated
RouterNavigatedAction
RouterRequestAction
- Route guards and route resolvers
- Route activated
RouterNavigationAction
RouterNavigatedAction
the default
RouterRequestAction
RouterNavigationAction
- Route guards and route resolvers
- The router state is rolled back to match the previous route
RouterCancelAction
orRouterErrorAction
RouterRequestAction
- Route guards and route resolvers
- The router state is rolled back to match the previous route
RouterCancelAction
orRouterErrorAction
Trigger: NavigationStart
Conditions:
- Trigger is caused by router navigation
Payload:
FullRouterSerializer
:{ event: NavigationStart }
MinimalRouterSerializer
:{ event: { id, url, urlAfterRedirects: undefined } }
Trigger:
- Early Navigation Action Timing:
RoutesRecognized
- Late Navigation Action Timing:
NavigationEnd
(just before theRouterNavigatedAction
)
Conditions:
- Trigger is caused by router navigation
Payload:
FullRouterSerializer
:
{
routerState: serialize(event)
event: new RoutesRecognized(event.id, event.url, event.urlAfterRedirects, serialize(event))
}
MinimalRouterSerializer
:
{ routerState, event: { id, url, urlAfterRedirects } }
Trigger: NavigationCancel
Payload:
FullRouterSerializer
:
{ storeState, event: NavigationCancel }
MinimalRouterSerializer
:
{ storeState, event: { id, url, urlAfterRedirects: undefined } }
Trigger: NavigationError
Payload:
FullRouterSerializer
:
{
storeState,
event: new NavigationError(event.id, event.url, event.toString())
}
MinimalRouterSerializer
:
{ storeState, event: { id, url, urlAfterRedirects: undefined } }
Trigger: NavigationEnd
Payload:
FullRouterSerializer
:
{
routerState: serialize(event),
event: NavigationEnd
}
MinimalRouterSerializer
:
{
routerState: serialize(event),
event: { id, url, urlAfterRedirects }
}
Trigger: NavigationStart
Conditions:
- Trigger is caused by router navigation
Effect: RouterStateSerializer#serialize(router.routerState.snapshot)
Trigger: NavigationStart
Conditions:
- Trigger is caused by router navigation
Effect: Update storeState
Trigger: Serialized router state snapshot { root: ActivatedRouteSnapshot + url: string }
and/or navigation ID change
Conditions:
- Snapshot isn't
null
orundefined
- Trigger isn't router navigation, that is state hydration somehow. This would probably not happen without actions that anyone can dispatch.
- Previous router event isn't a
NavigationStart
Router#url
isn't the same as the snapshot URL
Effect: Router#navigateByUrl(snapshot.url)