본문 바로가기

IT

[angular] passing static data to route.

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'];
}
);
}


'IT' 카테고리의 다른 글

[angular] Observable  (0) 2018.04.12
[angular] dynamic data with resolver  (0) 2018.03.29
[angular] passing static data to route.  (0) 2018.03.29
[angular] authGuard, canActivate, canActivateChild  (0) 2018.03.28
[angular] Outsourcing route config  (0) 2018.03.23
[angular] redirecting and wildcard  (0) 2018.03.23

태그