W3cubDocs

/Angular

withNavigationErrorHandler

function

Subscribes to the Router's navigation events and calls the given function when a NavigationError happens.

See more...

withNavigationErrorHandler(fn: (error: NavigationError) => void): NavigationErrorHandlerFeature

Parameters
fn (error: NavigationError) => void
Returns

NavigationErrorHandlerFeature: A set of providers for use with provideRouter.

See also

Description

This function is run inside application's injection context so you can use the inject function.

Further information is available in the Usage Notes...

Usage notes

Basic example of how you can use the error handler option:

const appRoutes: Routes = [];
bootstrapApplication(AppComponent,
  {
    providers: [
      provideRouter(appRoutes, withNavigationErrorHandler((e: NavigationError) =>
inject(MyErrorTracker).trackError(e)))
    ]
  }
);

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/router/withNavigationErrorHandler