此代码有效,但是当路线改变时不会更新,如何完成? 来自父组件的代码:
......
searchType : string;
searchTypeSubscription : Subscription;
constructor(
private route: ActivatedRoute,
private router: Router,
) { }
ngOnInit() {
this.searchTypeSubscription = this.route.firstChild.paramMap.subscribe(params => {
this.searchType = params.get("type")
})
console.log(this.searchType);
}
.......
路由的定义如下:
const ParentRoutes: Routes = [
{
path: 'parent', component: ParentComponent,
children: [
{
path: 'search/:type', component: ChildSearchComponent
},