Angular fallback route

Sami C.
Dec 15, 2020

--

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:

  1. Go into your app-routing.module.ts
  2. 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!

--

--