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