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..8cdd63731182 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 @@ -16,9 +16,9 @@ See the License for the specific language governing permissions and limitations under the License. -%> -import { ApplicationConfig, LOCALE_ID, importProvidersFrom } from '@angular/core'; +import { ApplicationConfig, LOCALE_ID, importProvidersFrom, inject } 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'; @@ -29,14 +29,26 @@ import './config/dayjs'; <%_ if (enableTranslation) { _%> import { TranslationModule } from 'app/shared/language/translation.module'; <%_ } _%> -import { httpInterceptorProviders } from 'app/core/interceptor/index'; +import { httpInterceptorProviders } from './core/interceptor'; import FindLanguageFromKeyPipe from 'app/shared/language/find-language-from-key.pipe'; import routes from './app.routes'; // jhipster-needle-angular-add-module-import JHipster will add new module here 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()); }