【发布时间】:2017-09-10 12:53:10
【问题描述】:
我有这些路线
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{
path: 'explore',
component: ExploreComponent,
children: [
{ path: '', component: ProductListComponent },
{ path: ':categorySlug', component: ProductListComponent }
]
}
];
这意味着用户可以去
/explore(无类别)
或
/explore/computers(类别computers)
从父级 (ExploreComponent),我希望能够订阅 categorySlug 参数更改,当然可以处理事件。我该怎么做?
编辑:
我尝试使用以下方式订阅:
this.activatedRoute.firstChild.params.subscribe(console.log);
它给了我我想要的东西,但是一旦我去/explore(没有类别)它就死了。它仅在使用/explore/:categorySlug 链接导航时有效。
【问题讨论】:
标签: javascript angular typescript