How to handle the exception if user is trying to access the page which not found. I'm going to explain how to handle a page not found exception in Angular 2,4,5.
In you RouterConfig add the following below line:
1
2
3
4
|
{
path: '**',
component: PageNotFoundComponent
}
|
And here is the whole route file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import { ModuleWithProviders } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { PopupComponent } from './popup/popup.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { AppComponent } from './app.component';
const appRoutes: Routes = [
{
path: '',
component: AppComponent
},
{
path: 'popup',
component: PopupComponent
}
,
{
path: '**',
component: NotFoundComponent
}
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
|
For more information about routing in Angular 2,4,5 click here.