• 개요
@angular/router

withNavigationErrorHandler

함수
안정화

Provides a function which is called when a navigation error occurs.

API

@paramhandler(error: NavigationError) => unknown
@returnsNavigationErrorHandlerFeature

A set of providers for use with provideRouter.

설명

Provides a function which is called when a navigation error occurs.

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

This function can return a RedirectCommand to convert the error to a redirect, similar to returning a UrlTree or RedirectCommand from a guard. This will also prevent the Router from emitting NavigationError; it will instead emit NavigationCancel with code NavigationCancellationCode.Redirect. Return values other than RedirectCommand are ignored and do not change any behavior with respect to how the Router handles the error.

사용 시 참고사항

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)))
    ]
  }
);
상세 내용으로 이동