要解决“Angular 8无法在延迟加载模块的次要(命名)出口上匹配任何路由”的问题,可以按照以下步骤进行操作。
loadChildren
属性来实现。例如,你的路由配置可能如下所示:const routes: Routes = [
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
];
@NgModule
装饰器的 entryComponents
属性来实现。例如,你的延迟加载模块可能如下所示:@NgModule({
declarations: [
LazyComponent, // 次要出口组件
],
entryComponents: [
LazyComponent, // 次要出口组件
],
})
export class LazyModule { }
outlet
属性来实现。例如,你的路由配置可能如下所示:const routes: Routes = [
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) },
{ path: 'lazy/:id', component: LazyComponent, outlet: 'secondary' } // 次要出口路由
];
router-outlet
元素来显示主要和次要(命名)出口的内容。例如,你的模板可能如下所示:
通过按照上述步骤操作,你应该能够在延迟加载模块的次要(命名)出口上匹配任何路由。