【发布时间】:2018-01-04 17:45:31
【问题描述】:
我正在将我们的 SPA 代码库从 Angular 2.0.0 升级到 2.4.10(Angular 路由器 3.4.10)。但是现在,最奇怪的事情发生了:有些路由工作得很好,但有些路由什么也没返回(比如一个空白组件),而且在我的任何调试前沿都绝对没有记录任何错误
这是我们实现的提炼版本:主要的“子”路由是延迟加载的,但后面的子路由是由加载的模块急切加载的
例子:
www.hostname.com/clients <- Lazy load
www.hostname.com/clients/details <- Eager loaded by the "Clients" module
我的主应用程序路由 (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);
然后在(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);
clientsRouting 常量随后被导入 ClientsModule 并传递给 imports:[] 装饰器。
现在www.hostname.com/clients 路由只返回一个空白组件。但是www.hostname.com/clients/test路由正常
现在我完全不知道出了什么问题。我什至比较了两个不同但相似的模块(一个有效,一个无效),但没有发现明显的编码差异。
项目中的所有组件都是这样实现的,并且在 Angular 2.0.0 上运行良好
编辑:更多信息:
- 我正在使用带有一些插件的 webpack 来进行丑化、lint 和其他一些小调整。在开发中,我们使用 webpack-dev-server (2.9.6) 来监听和重新编译代码,我们的配置,生产和开发都有这个问题。由于一些低级依赖关系,如果不先通过 webpack,我就无法运行应用程序,但我不认为 webpack 是这里的问题,我只是为了以防万一。
- 发生此错误时不会发生重定向,它只是原地不动,就像什么都没有(字面意思)发生一样。
- 我主要关注的 ATM 是
test子路由指向与''路由相同的模块,并且它可以工作,而直接''则不能;使用{ enableTracing: true }跟踪路线在两者之间没有任何区别。
【问题讨论】:
-
Leo 仅供参考,Angular 5 已经发布并支持 LTS :)
-
感谢您通知我!上次我检查它仍然是一个 RC,我会在我们的下一次重大更新中关注它!
-
它已经发展壮大并具有许多新功能和安全修复程序。我已经升级了我的 Angular 2 应用程序。它不再是 RC 了 :) 它是一个支持 LTS 的稳定版本
标签: angular angular2-routing lazy-loading upgrade