Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

withNavigationErrorHandler

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)))
    ]
  }
);