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