Skip to content

Commit

Permalink
handle agnular navigation errors
Browse files Browse the repository at this point in the history
updates #24396
  • Loading branch information
atomfrede committed Dec 10, 2023
1 parent 4aa14df commit dccf42d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions generators/angular/templates/src/main/webapp/app/app.config.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-%>
import { ApplicationConfig, LOCALE_ID, importProvidersFrom } from '@angular/core';
import { BrowserModule, Title } from '@angular/platform-browser';
import { RouterFeatures, TitleStrategy, provideRouter, withComponentInputBinding, withDebugTracing } from '@angular/router';
import { Router, RouterFeatures, TitleStrategy, provideRouter, withComponentInputBinding, withDebugTracing, withNavigationErrorHandler, NavigationError } from '@angular/router';
import { ServiceWorkerModule } from '@angular/service-worker';
import { HttpClientModule } from '@angular/common/http';

Expand All @@ -36,7 +36,19 @@ import routes from './app.routes';
import { NgbDateDayjsAdapter } from './config/datepicker-adapter';
import { AppPageTitleStrategy } from './app-page-title-strategy';

const routerFeatures: Array<RouterFeatures> = [withComponentInputBinding()];
const routerFeatures: Array<RouterFeatures> = [withComponentInputBinding(),
withNavigationErrorHandler((e: NavigationError) => {
const router = inject(Router);
if (e.error.status === 403) {
router.navigate(['/accessdenied'])
} else if (e.error.status === 404) {
router.navigate(['/404'])
} else if (e.error.status === 401) {
router.navigate(['/login']);
} else {
router.navigate(['/error']);
}
})];
if (DEBUG_INFO_ENABLED) {
routerFeatures.push(withDebugTracing());
}
Expand Down

0 comments on commit dccf42d

Please sign in to comment.