Return to site

ANGULAR INTERVIEW QUESTION: What is the purpose of path "**" route?

When you hit a URL not handled by your application, the Angular router will raise an exception.

The route '**" prevents such exception by defining a generic route catching any unhandled otherwise page URLs.

You add in your routes:

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

Put that route in the end because Angular process the routes in a top-down order:

const routes: Routes = [
  { path: 'user/:id', component: UserDetailComponent }, // Route 1
  { path: 'user', component: UserFormComponent },    // Route 2
  { path: '**', component: PageNotFoundComponent },   // Route 3
];