延迟加载“孙子”路线

时间:2018-11-01 15:03:28

标签: angular angular2-routing lazy-loading angular7

我正在努力延迟加载某些模块(使用Angular 7.x),并且想知道是否有可能为某种“孙代”路由设置路由-而不将其拆分为各自的模块

我的意思是说我有一个TemperatureModule,并且在其中有:

HotComponent
WarmComponent
CoolComponent
ColdComponent

是否可以从TemperatureModule的路由文件中延迟加载各种组件?

app-routing.module.ts

const appRoutes: Routes = [
    {
        path: 'temperature/',
        pathMatch: 'prefix',
        loadChildren: './temperature/temperature.module#TemperatureModule'
    }
];

export const AppRoutingModule: ModuleWithProviders = RouterModule.forRoot(appRoutes);

temperature.routing.module.ts

const temperatureRoutes: Routes = [
    {
        path: 'hot',
        component: HotComponent,
    },
    {
        path: 'warm',
        component: WarmComponent,
    },
    {
        path: 'cool',
        component: CoolComponent,
    },
    {
        path: 'cold',
        component: ColdComponent,
    },
];

export const TemperatureRoutingModule: ModuleWithProviders = RouterModule.forChild(temperatureRoutes);

0 个答案:

没有答案