Angular 6-路由到惰性模块的子模块不起作用

瓦尼奥

我正在尝试开发一个应用程序,其中根模块将显示将加载惰性模块的路由器链接的列表:

const appRoutes: Routes = [
{
 path: 'compose',
 component: ComposeMessageComponent,
 outlet: 'popup'
},
{
 path: 'admin',
 loadChildren: 'app/admin/admin.module#AdminModule',
 canLoad: [AuthGuard]
},
{
 path: 'crisis-center',
 loadChildren: 'app/crisis-center/crisis-center.module#CrisisCenterModule',
 data: { preload: true }
}
];

在这种特殊情况下,管理模块将具有两个路由器链接,用于其自身声明的组件,以及一个路由器链接,用于另一个模块(管理英雄):

const adminRoutes: Routes = [
  {
    path: '',
    component: AdminComponent,
    canActivate: [AuthGuard],
    children: [
      {
        path: '',
        canActivateChild: [AuthGuard],
        children: [
          { path: 'crises', component: ManageCrisesComponent },
          {path: 'heroes', component: ManageHeroesComponent},
          { path: '', component: AdminDashboardComponent }
        ]
      }
    ]
  }
];

我可以导航到所有路径,但是如果去找英雄并尝试导航到它自己的路线之一(例如零),则找不到页面。英雄路线如下所示:

const manageHeroesRoutes: Routes = [
  {
    path: '',
    component: ManageHeroesComponent,
    children: [
        { path: 'zeroes', component: ManageZerosComponent },
        { path: 'friends', component: ManageFriendsComponent }
    ]
  }
];

我注意到,如果我将管理员路由中的heroes路径替换为:

children: [
  { path: 'crises', component: ManageCrisesComponent },
  {path: 'heroes', loadChildren: 'app/admin/manage-heroes/manage-heroes.module#ManageHeroesModule'},
  { path: '', component: AdminDashboardComponent }
]

我可以进入英雄路线了。但是我想了解为什么不延迟加载ManageHeroes模块就不能访问它们。

这是到我的问题的复制到stackblitz的链接https://stackblitz.com/edit/angular-pm9wsz

谢谢。

罗德里戈

在路由路径中使用组件时,您将定义一个组件来处理此路由。Angular将仅加载该组件。在这种情况下,该组件位于其他模块中,但是角度不会加载其他任何模块iten,包括其路径。

当在路径路径定义中使用“加载子项”时,角度将延迟加载模块和itens,包括其内部路径。

https://angular.io/guide/lazy-loading-ngmodules

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

令牌未过期模块不起作用,Angular 6

Angular子模块子级路由不起作用。无法匹配任何路线

在根/主模块中使用时,子模块的 Angular 4 组件不起作用

Angular 6-为子模块导入共享模块

关于 angular2-jwt 的错误,找不到模块 'rxjs-compat/Observable(此模块在 Angular 6 中不起作用)

Angular 6子路线不起作用

Angular 6 主题订阅不起作用

routerLink在Angular 6中不起作用

Angular 6 numberonly指令不起作用

RouterLink在Angular 6中不起作用

Angular 6 * ngFor指令不起作用

Angular 6材质动画不起作用

Angular 6 routerLinkActive不起作用

在AppModule中提供Angular“ ErrorHandler”会导致惰性子模块路由中出现“找不到模块”

Angular 2路由显示在模块中分解时不起作用

Angular 7,命名路由器出口在延迟加载的模块中不起作用

rxjs 6 管道在 Angular 6 中不起作用

Angular2 RC6-带路由的嵌套模块

.NET MVC 5中的Angular 6应用程序,角路由不起作用

不能在Angular 6的子模块的app模块内部声明的指令使用

子模块中的Angular 6 routerlink和父模块中的router-out(app.component)

带有子模块的 Angular 4 路由

Javascript ES6模块不起作用

Angular 6-使用惰性加载模块时以反应形式出现问题

Angular 6 辅助路由

Angular 8 - 模块的延迟加载不起作用

Angular4模块范围不起作用

Kendo Angular2 UI Dropdownlist模块不起作用

Angular 12 - 延迟加载路径模块不起作用