小编Leo*_*aro的帖子

Angular 2路由返回空白页面,没有错误

我正在将我们的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 …
Run Code Online (Sandbox Code Playgroud)

lazy-loading upgrade angular2-routing angular

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular2-routing ×1

lazy-loading ×1

upgrade ×1