How to redirect at Home page if any router does not exist in Jhipster Angular 4 App?

1k Views Asked by At

I want to redirect at Home page if user type any URL which is not exist in system

2

There are 2 best solutions below

3
Jignesh M. Khatri On

You can use ** rule at the end of your navbar.routes to redirect to Home page. Below is the example:

{ path: '**', component: HomeComponent}
5
Jon Ruddell On

In app.module.ts, add the following line to the imports list, after the other modules. If it's added before other routes, it will redirect to home for those routes.

RouterModule.forChild([{ path: '**',   redirectTo: '/' }])

You'll also need to import RouterModule:

import { RouterModule } from '@angular/router';