小编ykr*_*vch的帖子

Angular2子模块的forChild()路由覆盖根路由

当使用loadChildren()调用导入子路由时,我遇到了覆盖根路由的问题.

申请路线声明为:

const routes: Routes = [
  { path: '', redirectTo: 'own', pathMatch: 'full' },
  { path: 'own', component: OwnComponent },
  { path: 'nested', loadChildren: () => NestedModule},
];
export const routing = RouterModule.forRoot(routes);
Run Code Online (Sandbox Code Playgroud)

嵌套子模块的路由:

const routes: Routes = [
  { path: 'page1', component: NestedPage1Component },
  { path: 'page2', component: NestedPage2Component },
  { path: '', redirectTo: 'page1', pathMatch: 'full' },
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class Module1RoutingModule {}
Run Code Online (Sandbox Code Playgroud)

我可以获得/拥有,/ nested/page1,/ nested/page2,但是当我尝试获取root /时,我正在重定向到/ page1.为什么会发生这种情况,因为它在带有RouterModule.forChild的子模块中声明,它如何重定向到/拥有?

我为repro创建了简单的插件 - https://plnkr.co/edit/8FE7C5JyiqjRZZvCCxXB?p=preview

有人经历过这种行为吗?

angular2-routing angular

4
推荐指数
1
解决办法
3891
查看次数

标签 统计

angular ×1

angular2-routing ×1