更新
看起来这不应该在角5上工作,但出于某种原因。这个
loadChildren
值必须是纯字符串,或
LoadChildrenCallback
. 我已经尝试过回调-有可观的-但正如许多问题指出,这总是打破懒惰加载。使用普通字符串选项
在使用CLI v6更新到Angular 6之后。
我有一个延迟加载的路径设置如下
import { BLOG_CONFIG } from './BLOG_CONFIG';
const blogPath = BLOG_CONFIG.blogPath;
const categoriesPath = BLOG_CONFIG.categoriesPath;
const categoriesModulePath = BLOG_CONFIG.categoriesModulePath;
const routes: Routes = [
{ path: `${blogPath}/${categoriesPath}`, loadChildren: categoriesModulePath }
];
博客配置为:
export const BLOG_CONFIG = {
blogPath: 'blog',
postsPath: 'post',
categoriesPath: 'categories',
categoriesModulePath: './modules/categories/categories.module#CategoriesModule',
}
当我导航到
blog/categories
路由,存在控制台错误:
ERROR Error: Uncaught (in promise): Error: Cannot find module "./modules/categories/categories.module.ngfactory".
Error: Cannot find module "./modules/categories/categories.module.ngfactory".
如果我改变路线
加载子级
直接使用字符串就可以了!
const routes: Routes = [
{ path: `${blogPath}/${categoriesPath}`, loadChildren: './modules/categories/categories.module#CategoriesModule' }
];
这不是发生在角度5。我是不是错过了一些简单的东西!?
注意:当它与字符串一起工作时,我将获得
ng serve --aot
chunk {modules-categories-categories-module-ngfactory} modules-categories-categories-module-ngfactory.js, modules-categories-categories-module-ngfactory.js.map (modules-categories-categories-module-ngfactory) 70.5 kB [rendered]
我想这是
webpack
读取BlogConfig对象可能有问题,但不确定