IT
[angular] passing static data to route.
로바아토
2018. 3. 29. 16:11
We can set the static data in route.module
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'users', component: UsersComponent, children: [
{ path: ':id/:name', component: UserComponent }
]},
{ path: 'servers', canActivateChild: [AuthGuard], component: ServersComponent, children: [
{ path: ':id', component: ServerComponent },
{ path: ':id/edit', component: EditServerComponent, canDeactivate:[CanDeactivateGuard]}
]},
//{path: 'not-found', component: PageNotFoundComponent},
{path: 'not-found', component: ErrorPageComponent, data: {message: 'Page not found!'}},
{path: '**', redirectTo: '/not-found'}
];
like this.
{path: 'not-found', component: ErrorPageComponent, data: {message: 'Page not found!'}},
retrieve the data like this.
ngOnInit() {
this.errorMessage = this.route.snapshot.data['message'];
this.route.data.subscribe(
(data:Data) => {
this.errorMessage = data['message'];
}
);
}