angular - 文件中的多个路由器插座不适用于延迟加载
问题描述
我有这样的 app-component.html 文件:
<router-outlet></router-outlet>
<router-outlet name="menu"></router-outlet>
我的 app-routing.ts 是这样的:
{ path: '', loadChildren: () => import('./features/home/home.module').then(m => m.HomeModule) },
{ path: '', outlet: 'menu', loadChildren: () => import('./features/catalog/catalog.module').then(m => m.CatalogModule)}
但是当我启动我的应用程序时,我遇到了这个错误:
core.js:4352 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'routes' of undefined
TypeError: Cannot read property 'routes' of undefined
at getChildConfig (router.js:3046)
似乎这是一个已知错误并且它无法正常工作,所以我尝试了这个:
{
path: '',
outlet: 'menu',
component: MenuProxyRouteComponent,
children: [{
path: 'test',
loadChildren: () => import('./features/catalog/catalog.module').then(m => m.CatalogModule)
},
{ path: '**', redirectTo: 'test', pathMatch: 'full' }
]
},
使用我的 MenuProxyRouteComponent:
import { Component } from '@angular/core';
@Component({
selector: 'menu-proxy-route',
template: '<router-outlet></router-outlet>',
})
export class MenuProxyRouteComponent {
}
我没有以前的错误,但现在我有这个:
ERROR in src/renderer/app/features/menu/menu.proxy.component.ts:5:16 - error NG8001: 'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular component, then verify that it is part of this module.
2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
5 template: '<router-outlet></router-outlet>',
我不明白为什么会出现此错误,因为我在 app.component.html 文件中有一个并且它工作正常。
任何人都知道如何在 app.component.html 中使用多个延迟加载?或者为什么我有第二个错误?
谢谢
解决方案
我将用一个例子来解释它。对于这个多router-outlet
<router-outlet name="left"></router-outlet>
<router-outlet name="right"></router-outlet>
尝试更改app-routing.module
或相关的路由文件如下
{
path: 'list',
component: LeftComponent,
outlet: 'left'
},
{
path: ':id',
component: RightComponent,
outlet: 'right'
}
推荐阅读
- c# - Automapper 缺少类型映射配置或不支持的映射?ASP>NET MVC
- audio - 如何在视频文件的音频中修改音乐音高并且仍然听起来自然
- javascript - Linkedin api V2 在节点 JS 中上传视频
- aws-api-gateway - API Gateway 日志:修改日志名称
- excel - Excel VBS 错误:关系“andmebaas”不存在
- android - 从 Chrome 重定向到带有位置标头的 302 后被阻止的 Android 应用
- angular - 如何从中获取纯文本
使用表单控件?我无法得到它。文本保存在 xyz
福尔梅 - javascript - 防止全屏菜单滚动
- java - 如何将 JUnit 测试从一个 Maven 项目导入另一个?
- ios - 在堆栈视图中带有堆栈视图的水平集合视图在重新加载动画时隐藏内部堆栈视图