angular - 特性模块中的延迟加载 - Angular
问题描述
该应用程序留在这里:https ://angular-dqpbqa.stackblitz.io 。我在做什么错?它最初也会加载英雄列表,但路径是''。
功能模块的延迟加载不起作用。我在每个功能模块中创建了单独的路由。使用 loadchildren 属性动态加载模块
const routes: Routes = [
{ path: 'dashboard',
loadChildren: () => import('./dashboard/dashboard.module').then(mod =>
mod.DashboardModule)
},
{ path: 'heroes',
loadChildren: () => import('./heroes/heroes.module').then(mod =>
mod.HeroesModule)
},
{ path: 'detail/:id',
loadChildren: () => import('./hero-detail/hero-detail.module').then(mod
=> mod.HeroDetailModule)
},
{
path: '',
redirectTo: '',
pathMatch: 'full'
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
stackblitz 可编辑:https ://stackblitz.com/edit/angular-dqpbqa
解决方案
HeroesModule 不是延迟加载的,因为它是在app.module.ts
<= 中导入的,这是错误的
@NgModule({
imports: [ /* ... */ HeroesModule, /* ... */ ]
})
export class AppModule { }
在那里,HeroesModule 最初被加载并且应用程序可以访问heroes-routing.module.ts
因此,当您导航到 时''
,该路径将与''
您在heroes-routing.module.ts
其中显示的路径匹配HeroesComponent
推荐阅读
- jquery - jQuery将对象数组中的多个元素添加到HTML中
- android - 如何修复 android 模拟器 (goldfish kernel + android-9) 启动循环中的 sepolicy 错误
- sqlite - CN1 DAO 不断失败,原因不明
- java - 每当我尝试输入我的设置时,logcat 都会向我显示此错误,我不知道出了什么问题
- batch-file - 詹金斯 - cmd无法识别
- python - numpy tofile 在每一行中放置单引号
- javascript - 循环常量,让图声明......如何解决?
- python - 将列表的最后两个整数的总和附加到同一个列表
- html - 是否可以仅使用引导程序来实现此布局?
- java - 使用 JavaAssist 修改现有类时出错