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

5
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';
3
On

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

{ path: '**', component: HomeComponent}