简体   繁体   English

如何延迟加载子路由?

[英]How to lazy load children routes?

I would like to configure my routing like this:我想像这样配置我的路由:

const routes: Routes = [
    {
        path: ':angebotsNummer',
        loadChildren: './uebersicht/uebersicht.module#UebersichtModule',
        resolve: { angebotReadModel: AngebotReadModelResolver },
        children: [
            {   path: 'konditionen',
                loadChildren: './konditionen/konditionen.module#KonditionenModule',
            }
        ]
    }
]

This would result in the child url :angebotsNummer/konditionen这将导致子网址:angebotsNummer/konditionen

Doing so, angular is telling me: Error: Invalid configuration of route ':angebotsNummer': children and loadChildren cannot be used together这样做,角度告诉我: Error: Invalid configuration of route ':angebotsNummer': children and loadChildren cannot be used together

So this will not work.所以这行不通。 How can I lazy load childrenroutes in angular, if at all?如果有的话,我如何以角度延迟加载 childrenroutes?

In that case you would add that configuration in the lazy module routing (Uebersicht-routing.module.ts)在这种情况下,您可以在惰性模块路由(Uebersicht-routing.module.ts)中添加该配置

const routes: Routes = [
{
    path: '',
    children: [
        {   path: 'konditionen',
            loadChildren: './konditionen/konditionen.module#KonditionenModule',
        }
    ]
}]

And remove the children part you have:并删除您拥有的儿童部分:

const routes: Routes = [
    {
        path: ':angebotsNummer',
        loadChildren: './uebersicht/uebersicht.module#UebersichtModule',
        resolve: { angebotReadModel: AngebotReadModelResolver }
    }]

if you have a如果你有一个

    loadChildren: './uebersicht/uebersicht.module#UebersichtModule',

then you have an inner router inside that module that does那么你在那个模块中有一个内部路由器

component: UbersichtComponent

the component is the one able to carry children, the loadChildren is routing you to a nested module, but the component-loader is the one able to hold children of its own组件是能够携带孩子的组件,loadChildren 将您路由到嵌套模块,但是组件加载器是能够拥有自己的孩子的组件

You can do like as below:你可以像下面这样:

const routes: Routes = [
    {
        path: ':angebotsNummer',
        component: 'UebersichtComponent',
        resolve: { angebotReadModel: AngebotReadModelResolver },
        children: [
            {   path: 'konditionen',
                loadChildren: () => import('./+konditionen/konditionen.module').then(m => m.KonditionenModule),
            }
        ]
    }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM