How to configure Angular route to redirect to a default route if the user goes to a non existent route?
I’m working with Angular 11, following steps:
- Go into your app-routing.module.ts
- In your routes Array add a new object:
{path: '**', redirectTo: '', pathMatch: 'full'}
Mine looks like this:
const routes: Routes = [{path: '', component: HomeComponent, pathMatch: 'full'}, {path: '**', redirectTo: '', pathMatch: 'full'}];
That’s all, save and try to visit a URL that does not exist, you should be redirected.
Cheers!