您能举例说明如何从路由获取数据。 Routing & Navigation
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'hero/:id', component: HeroDetailComponent },
{
path: 'heroes',
component: HeroListComponent,
data: { title: 'Heroes List' } // <--- How to use this data?
},
{ path: '',
redirectTo: '/heroes',
pathMatch: 'full'
},
{ path: '**', component: PageNotFoundComponent }
];
谢谢
答案 0 :(得分:1)
您可以在组件/服务构造函数中使用ActivatedRoute
。
例如:
public class MyAppComponent{
data: any;
constructor(route: ActivatedRoute){
this.data = route.snapshot.data;
}
}
您可以找到更多详情here。