Angular 11中的loadChildren路由中需要使用箭头函数,否则会报错。以下是示例代码:
原始代码:
const routes: Routes = [
{ path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
];
修改后的代码:
const routes: Routes = [
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
];
通过使用箭头函数,路由可以正确加载懒加载模块。