[英]Angular 8 - Lazy Loading of Module not working
如https://stackblitz.com/edit/angular-qbbhgp所示,我试图实现一个非常简单的路由,其中涉及模块的延迟加载。 当我点击“链接”时,它似乎不起作用。 我希望看到“Student Page”这个词出现,但它没有发生。
请注意,我希望解决方案涉及使用 import api(延迟加载模块的较新语法)
这是因为您还没有在学生模块中添加路由。
你的 stackblitz 的分支: https ://stackblitz.com/edit/angular-zrnrxj
student 模块在声明路由时需要使用.forChild()
,因为它是一个子模块。
const routes:Routes = [
{ path: '', component: StudentComponent }
]
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes)
],
declarations: [StudentComponent]
})
export class StudentModule { }
您还没有为Student.routing.module
提供Routes
吗?
由于您已经指导了student.module
,但您可能没有从那里提供您所展示的组件。
如果您尚未创建到Student.routing.module
,请创建一个并在同一模块中提供默认路由。
const routes: Routes = [
{path: '', component:StudentComponent } ];
您必须定义延迟加载模块的路由并指定延迟加载模块的根组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.