【问题标题】:navigate in a loadchildren path doesn't work在 loadchildren 路径中导航不起作用
【发布时间】:2020-06-22 09:28:15
【问题描述】:

我有一个非常简单的项目设置,但是我无法使用 loadchildren 导航到延迟加载路径...

app-routing.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 {}

list-monitor.component.ts:

onItemTap(currentMonitorListeElem: MonitorListeElem){
    this.routerExt.navigate(['messwerte',currentMonitorListeElem.id ], {transition: {name: 'slideLeft'}, relativeTo: this.route});
}

当执行onItemTap 函数时,我得到错误:
错误:无法匹配任何路由。 URL 段:'system/monitorliste/messwerte/421'

这不是完全正确的路线还是我完全错误的理解?

非常感谢!

编辑: 编辑 system-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”,我被困在“系统”中

使用时:
系统路由.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”

【问题讨论】:

标签: angular angular-ui-router nativescript lazy-loading


【解决方案1】:

原因是 "messwerte/:id" 不是 "monitorliste" 的子节点,您会收到错误“无法匹配任何路由”。

{
  path: "monitorliste",
  component: ListeMonitorComponent,
  children: [{ path: "messwerte/:id", component: DatenMonitordatenComponent }]
},

另请注意,可以使用延迟加载的新方法,例如

loadChildren: () => import('./crm/crm.module').then(m => m.CrmModule)

【讨论】:

  • 所以我理解错了?我想当我这样做时,它会懒惰地加载system-routing.module.ts 的所有路由。所以我可以使用子路由来延迟它们被加载到点击/调用时的时间。但您建议将儿童的“更深一层”。 (messwert/:id 作为 monitorliste 的子项)这可以解释为什么当我使用编辑后的 ​​system-routing.module.ts 时它不起作用,你能看看我的想法是对还是错?
猜你喜欢
  • 2021-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-09
  • 2022-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多