我想为具有不同参数的不同路径使用相同的一个组件。像这样:
export const appRoutes:Routes = [
{ path: 'rss', component: RssComponent(1) },
{ path: 'vk', component: RssComponent(2) }
];
有可能吗?
答案 0 :(得分:2)
您无法传递构造函数参数,但可以传递data
export const appRoutes:Routes = [
{ path: 'rss', component: RssComponent, data: {id: 1} },
{ path: 'vk', component: RssComponent, data: {id: 2} }
];
class RssComponent {
constructor(private route:ActivatedRoute) {
route.data.subscribe(d => {
console.log('Route data id:', d);
}
}
}