Skip to content

Commit

Permalink
handle agnular navigation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
atomfrede committed Dec 11, 2023
1 parent fdec0db commit 5018b70
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions generators/angular/templates/src/main/webapp/app/app.config.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<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 5018b70

Please sign in to comment.