首页 文章

Angular 4中具有根路由器插座的嵌套路由

提问于
浏览
2

我在Angular 4应用程序中使用嵌套路由 . 它们的结构如下:

routes = [
  {
    path: 'parent',
    component: ParentComponent,
    children: [
      {
        path: 'child',
        component: ChildComponent,
        children: [
           path: 'grandchild',
           component: GrandchildComponent
        ]
      }
    ]
  }
]

我在app.component.html中定义了一个路由器插座 .

当我导航到'父/子'路线时,此设置正常,路由器插座加载ChildComponent .

但是,当我导航到'父/子/孙子'路径时,GrandchildComponent不会加载 .

这似乎适用于子组件中的辅助路由器插座,但有没有办法可以让GrandchildComponent加载到根路由器插座上,而不需要辅助路由器插座?

1 回答

  • 1

    我会说不 .

    如果你想在根插座中加载孙子,那么它不是孙子,它是祖父母!当您有嵌套路由时,您需要具有嵌套出口 .

相关问题