1
假设我有以下路线:订阅基于路线导航中角2数据变化
[
{
path: 'view',
children: [
{
path: ':id',
component: CustomerViewComponent,
resolve: {
customerViewData: CustomerResolve,
edit: ViewRouteResolve // Returns false
},
data: {
other: false
},
children: [
{
path: 'edit',
resolve: {
edit: EditRouteResolve // Returns true
},
data: {
other: true
}
},
{
path: '',
data: {
other: false
}
}
]
}
]
},
{ path: '', component: CustomerListComponent }
]
我想使用CustomerViewComponent
为/视图/和/视图/ 1 /编辑
的问题是我无法在我的组件中捕获这些数据更改。我曾尝试与resolve
或data
,我不能捕获任何变化......如预期
此代码将不会触发:
this.route.data.subscribe(m => {
debugger; // Triggers only once the view loads, then never again
});
// This triggers quite often, but the data is always stale.
this.router.events.subscribe(m => {
console.log(this.route.snapshot.data['edit']);
console.log(this.route.snapshot.data['other']);
debugger;
});
难道这是一个错误?我唯一的解决办法是看事件NavigationEnd和分析的.url字符串属性...
我很欣赏的答案。 'this.route'实际上是'ActivatedRoute',我没有看'params',而是'data'。 – jsgoupil
哦,对。然后看看这个答案http://stackoverflow.com/a/38652281/3159399 –
哇,这是一个这样一个丑陋的设计...我一直在浏览GitHub上的错误,他们都通过设计关闭它们。有多人报告同样的问题......这是一个设计问题。 – jsgoupil