user6123723 user6123723 - 3 months ago 32
TypeScript Question

Angular 2 RC5 and above - How to show an error page when no route matches?

My current Route config looks like this

{
path: '',
redirectTo: 'register/self',
pathMatch: 'full'
},
{
path: 'register/self',
component: SelfRegisterComponent
},
{
path: 'register/auto/:Id',
component:AutoregisterComponent
},


If a user tries to navigate to '/register/auto'. Currently I see a blank page and an error in the console.
How can I show a 404 error or a message saying that this page is not available globally?

Answer

See angular2 cheatsheet You can do something like this:

{path: '**', redirectTo: '/404' }

So for example you would have something probably like this:

{path: '/404', component: NotFoundComponent},
{path: '**', redirectTo: '/404' }

Hope that helps