Angular LoadChildren 字符串格式已弃用,但函数格式会导致错误

标签 angular angular-cli angular-router

Angular 8(随时都会发布)不推荐使用字符串格式来路由 LoadChildren,如下所示: 类型 LoadChildren = LoadChildrenCallback |已弃用LoadChildren;来自 https://next.angular.io/api/router/LoadChildren

使用 JIT 的 DEV 中一切都很好,但是使用 AOT 的 --prod 中的延迟加载模块在尝试路由到该模块时会抛出以下错误:

错误错误:未捕获( promise 中):错误:未加载运行时编译器

我现在可以继续使用字符串格式并忽略弃用警告,但最好能够绕过弃用警告并拥有正常运行的代码。

工作字符串方法:

{
   path: 'admin',
   loadChildren: './admin/admin.module#AdminModule'
},

失败函数方法:

{
   path: 'admin', 
   loadChildren: ():Promise<typeof AdminModule> =>
       import('./admin/admin.module').then(m => m.AdminModule)
},

我在最近的几个 beta 版和 rc 版中都遇到过这个问题。

还有其他人找到解决此问题的方法吗?

最佳答案

你尝试过这样的事情吗?

[{
  path: 'lazy',
  loadChildren: () => import('./lazy-route/lazy.module').then(mod => mod.LazyModule),
}];

该链接适用于 Angular 的最新版本,但它可能会提供一些帮助。 https://angular.io/api/router/LoadChildrenCallback

关于Angular LoadChildren 字符串格式已弃用,但函数格式会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56243515/

相关文章:

angular-cli - 如何从外部原理图调用 ng add

Angular 7 Route 动画在嵌套路由器 socket 中不起作用

angular - ngrx 在组件(与路由关联)init 上调度操作

javascript - 将 node-sass-json-importer 集成到 Angular CLI 应用程序中

javascript - 有没有办法将今天的日期替换为小时?

angular - Font Awesome 5 : Could not find icon money-check

angular - 如何发布到github页面?

angular - ExpressionChangedAfterItHasBeenCheckedError 在 Angular 6 的 ngInit 中调用 toastr

javascript - 在没有节点服务器的情况下使用 angular-cli 在 Chrome 上运行本地构建的 angular 2 应用程序

angular - 您是否需要取消订阅对 Angular 中的路由器参数的订阅?