0

我的计划是建立一个项目,其中“/”上的主网站非常庞大,只是在实际登录后才延迟加载。

const routes: Routes = [
  { path: '', canLoad: [AuthGuard], loadChildren: './home/home.module#HomeModule' },
  { path: 'login', component: LoginComponent },
  { path: '**', redirectTo: '/'  },
];

但是 CanLoad 似乎有这个限制,它不适用于“/”,因为发生的情况是应用程序陷入无限循环。当 canLoad 被拒绝时,CanLoad 具有内置的自动重定向到 '/',即使您在“false”时重定向到 '/login' 也是如此。

我的临时解决方案是不使用 '' root 作为路由,而是将其称为 '/home' 或其他名称,但这会在应用程序的每条路由前面添加 /home/。

CanActivate 守卫在这个设置下工作,但是当然我没有得到延迟加载的好处,因为无论如何都会加载完整的应用程序(home/),即使用户只会卡在 /login 屏幕上。

有关的:

https://github.com/angular/angular/issues/16197

https://github.com/angular/angular/issues/24715

4

1 回答 1

0

编辑:将“登录”路线移动到数组中的第一个位置。

于 2019-02-13T06:06:34.467 回答