-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Description
Which @angular/* package(s) are relevant/related to the feature request?
router
Description
This is a followup of #48295.
There is no replacement for ExtraOptions with new provideRouter
eg
RouterModule.forRoot(APPLICATION_ROUTES, {
errorHandler: (error: any) => console.error('Router Error Occured', error)
}),
The linked issue mentioned you can use the Router.events with NavigationError but this is not usable for all variants of handling navigation errors.
The defaultErrorHandler is throwing the error and can't be overwritten:
angular/packages/router/src/router.ts
Lines 169 to 171 in 61e69c8
| function defaultErrorHandler(error: any): any { | |
| throw error; | |
| } |
angular/packages/router/src/router.ts
Lines 977 to 987 in 61e69c8
| this.restoreHistory(overallTransitionState, true); | |
| const navError = new NavigationError( | |
| overallTransitionState.id, | |
| this.serializeUrl(overallTransitionState.extractedUrl), e, | |
| overallTransitionState.targetSnapshot ?? undefined); | |
| eventsSubject.next(navError); | |
| try { | |
| overallTransitionState.resolve(this.errorHandler(e)); | |
| } catch (ee) { | |
| overallTransitionState.reject(ee); | |
| } |
For the moment the best way is to use an own provide for the ROUTER_CONFIG injection token.
Proposed solution
Add new settings to Router config
provideRouter(APPLICATION_ROUTES, withRouterConfig({
errorHandler: (error: any) => console.error('Router Error Occured', error)
})),
Alternatives considered
There is non if you want to fluent API.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels