簡體   English   中英

Angular v6-延遲加載的路由未加載

[英]Angular v6 - Lazy Loaded Routes Not Loading

更新

看來這不應該在Angular 5中起作用-但是出於某種原因。 loadChildren值必須為純字符串或LoadChildrenCallback 我已經嘗試過使用Observable進行回調,但是由於許多問題指出,這總是會破壞延遲加載。 僅使用純字符串選項


在使用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".

如果我更改路線,以便loadChildren 直接使用字符串,則可以!

const routes: Routes = [
  { path: `${blogPath}/${categoriesPath}`, loadChildren: './modules/categories/categories.module#CategoriesModule' }
];

這不是在Angular 5中發生的。我在這里錯過了一些簡單的東西嗎?

注意:當它與字符串一起使用時,我會獲得ng serve --aot的CLI輸出

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]

我認為也許是通過閱讀BlogConfig對象是一個webpack問題,但不確定

嘗試

loadChildren: BLOG_CONFIG.categoriesModulePath 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM