diff --git a/generators/angular/templates/src/main/webapp/app/app.config.ts.ejs b/generators/angular/templates/src/main/webapp/app/app.config.ts.ejs index c1b5993ab170..86fe0479c7da 100644 --- a/generators/angular/templates/src/main/webapp/app/app.config.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/app.config.ts.ejs @@ -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'; @@ -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 = [withComponentInputBinding()]; +const routerFeatures: Array = [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()); }