angular - 在 loadchildren 路径中导航不起作用
问题描述
我有一个非常简单的项目设置,但是我导航到带有 loadchildren 的延迟加载路径不起作用......
应用程序路由.module.ts:
const routes: Routes= [
{path:'', redirectTo: 'auth', pathMatch: 'full'},
{path:'auth', component: AnmeldungComponent},
{path:'system', loadChildren: '~/app/system/system.module#SystemModule'},
{path:'settings', component: SettingsComponent}
];
@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule {}
系统路由.module.ts:
const routes: Routes = [
{
path: "",
component: ListeSystemComponent,
},
{ path: "monitorliste", component: ListeMonitorComponent },
{ path: "messwerte/:id", component: DatenMonitordatenComponent },
{
path:
"messwertverlauf/:schwelleAlert/:schwelleGut/:schwelleWarn/:schwelleRichtung/:id",
component: MesswertverlaufComponent,
},
];
@NgModule({
imports: [NativeScriptRouterModule.forChild(routes)],
exports: [NativeScriptRouterModule],
})
export class SystemRoutingModule {}
列表-monitor.component.ts:
onItemTap(currentMonitorListeElem: MonitorListeElem){
this.routerExt.navigate(['messwerte',currentMonitorListeElem.id ], {transition: {name: 'slideLeft'}, relativeTo: this.route});
}
执行onItemTap
函数时出现错误:
错误:无法匹配任何路由。URL 段:'system/monitorliste/messwerte/421'
这不是完全正确的路线还是我完全理解错了?
非常感谢!
编辑:编辑系统-routing.module.ts:
const routes: Routes = [
{
path: "",
component: ListeSystemComponent,
children: [
{
path: "monitorliste",
component: ListeMonitorComponent,
children: [
{
path: "messwerte/:id",
component: DatenMonitordatenComponent,
},
{
path:
"messwertverlauf/:schwelleAlert/:schwelleGut/:schwelleWarn/:schwelleRichtung/:id",
component: MesswertverlaufComponent,
},
],
},
],
},
];
当我这样使用它时,我什至无法到达“monitorliste”并且我被困在“系统”中
使用时:
system-routing.module.ts:
const routes: Routes = [
{
path: "",
component: ListeSystemComponent,
},
{
path: "monitorliste",
component: ListeMonitorComponent,
children: [
{
path: "messwerte/:id",
component: DatenMonitordatenComponent,
},
{
path:
"messwertverlauf/:schwelleAlert/:schwelleGut/:schwelleWarn/:schwelleRichtung/:id",
component: MesswertverlaufComponent,
},
],
},
];
我可以到达“monitorliste”,但我无法到达“messwerte/:id”,而是被重定向到“monitorliste”
解决方案
原因是“messwerte/:id”不是“monitorliste”的子级,并且您会收到错误“无法匹配任何路由”。
{
path: "monitorliste",
component: ListeMonitorComponent,
children: [{ path: "messwerte/:id", component: DatenMonitordatenComponent }]
},
另请注意,可以使用延迟加载的新方法,例如
loadChildren: () => import('./crm/crm.module').then(m => m.CrmModule)
推荐阅读
- flutter - Flutter - 类似于 Youtube (Android) 的 PIP 模式
- php - 具有不同环境的同一服务器上的多个队列(Laravel Forge)
- linux - Samba 给出“功能未实现”错误
- c# - 在 Windows 服务应用程序中运行 python 脚本(没有用户登录)
- python - 是否可以在名称中声明带有参数的关键字?
- xamarin - Xamarin - 防止新的 ios 13 表单样式演示
- c - 如何使用 MPI 修复 C 中的 AES 解密
- html - 如何在 Flexbox 中的两个 div 之间添加边距/空间
- java - 我正在打印素数数组,我的代码输出是 2,它没有迭代
- java - 将带有嵌套对象的 JSON 映射到 GSON