Plunker:https://plnkr.co/edit/GyUApIPQzTvp9vIahYdT?p=preview如何在Angular中使用子路由延遲加載錯誤路由?
我有路線設置這樣的app.module
:
const routes = [
{
path: '',
component: DummyComponent
},
{
path: '', // is this right?
component: SingleComponent,
children: [
{
path: '**', // is this right?
loadChildren: 'src/lazy/lazy.module#LazyModule'
}
]
}
];
而且在lazy.module
我有
const routes = [
{
path: '**', // is this right?
component: LazyComponent
}
];
的問題是,SingleComponent
(頁面模板)的實際加載,但頁面內容(LazyComponent
)未加載。 (點擊notfound
鏈接查看Plunker的結果)
我應該如何配置這個以便SingleComponent
(模板)和LazyComponent
(內容)加載正確顯示頁面?
注意:此LazyComponent
被認爲是一個錯誤頁面,所以我要趕你在做什麼這裏調用/虛擬和/ NOTFOUND路線的所有路由(/notfound
,/invalid-url
,/<anything that doesn't exist in router>
)
你應該在你的應用程序的頂層添加你的'path:'**''route綁定到你的錯誤組件,a最後的路線。這意味着如果在這個匹配器之前沒有發現任何東西,你會得到這條路徑(這是你想要的一個未找到的頁面)。 – Supamiu