Joh*_*kel 5 routes rxjs angular angular-router
问题是当我在两个相似的 URL 之间导航时,我的组件没有重新绘制。例如,当用户查看http://localhost:8088/#/app/route/study/6/detail
然后导航到 时http://localhost:8088/#/app/route/study/7/detail
,StudyComponent
会正确地重新加载。但是,DetailComponent
未重新加载。我认为原因是params
细节没有改变,所以Angular认为不重新加载就可以了。但就我而言,详细信息取决于父 params。
我怎样才能解决这个问题?
我的路线:
const studyRoutes: Routes = [
{
path: '', component: RouteComponent,
children: [
{path: 'study/:id', component: StudyComponent,
children: [
{path: 'detail', component: DetailComponent },
{path: 'parts', component: PartsComponent }
]
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
我的所有组件都是这样初始化的:
ngOnInit() {
this.loader = this.route.params.subscribe(params => this.onLoad());
}
ngOnDestroy() {
this.loader.unsubscribe();
}
Run Code Online (Sandbox Code Playgroud)
当我在不同研究的细节之间导航时,从未onLoad
在DetailComponent
.
:id
要对级别参数的更改做出反应DetailComponent
,您需要执行以下更改:
// detail.component.ts
ngOnInit() {
this.loader = this.route.parent.params.subscribe(params => this.onLoad());
}
Run Code Online (Sandbox Code Playgroud)
detail
这是因为路由中的路径没有定义:id
参数,而是它的父路径定义了参数。因此,更改会反映在路由器状态树的该级别上。
归档时间: |
|
查看次数: |
6387 次 |
最近记录: |