Leo*_*aro 2 lazy-loading upgrade angular2-routing angular
我正在将我们的SPA代码库从角度2.0.0升级到2.4.10(Angular router 3.4.10).但是现在,最奇怪的事情正在发生:一些路由工作正常,但有些路由没有返回任何内容(如空白组件),并且在我的任何调试前端都记录了绝对没有错误
这是我们实现的提炼版本:主要的"子"路由是延迟加载的,但是下面的子路由被加载的模块急切加载
例:
www.hostname.com/clients <- Lazy load
www.hostname.com/clients/details <- Eager loaded by the "Clients" module
Run Code Online (Sandbox Code Playgroud)
我的主应用程序路径上有以下代码(src/app/app.routing.ts):
import { Routes, RouterModule } from '@angular/router';
const appRoutes: Routes = [
{ path: 'clients', loadChildren: () => System.import('../clients/clients.module').then(m => m['ClientsModule']) },
...moreRoutes
];
export const appRouting = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)
然后在(src/clients/clients.routing.ts)中:
import { Routes, RouterModule } from '@angular/router';
import { Clients } from './'; // I have a index.ts file that exports the component plus some more stuff, so loading from this relative path works just fine
const clientRoutes: Routes = [
{ path: 'test', component: Clients }, // for testing porpuses
{ path: '', component: Clients }, // "Normal" route that should work like in all my other modules
...MoreRoutes
];
export const clientsRouting = RouterModule.forChild(clientRoutes);
Run Code Online (Sandbox Code Playgroud)
然后将clientsRouting const导入ClientsModule并传递给imports:[]装饰器.
现在路由www.hostname.com/clients只返回一个空白组件.但路线www.hostname.com/clients/test正常
现在我完全不知道出了什么问题.我甚至比较了两个不同但相似的模块(一个工作,另一个没工作),但没有发现明显的编码差异.
项目中的所有组件都是这样实现的,并且在Angular 2.0.0上运行良好
编辑:更多信息:
test点是,子路由指向与路由相同的模块'',并且它起作用,而直接路由''不起作用; 跟踪路线的方式与{ enableTracing: true }两者之间没有任何差别.