Angular 7子路由替换父组件

时间:2019-06-20 08:28:12

标签: angular angular7 angular-routing angular7-router

我有这样声明的路线:

const appRoutes: Routes = [
  {
    path: '',
    component: AppComponent,
    children: [
      {
        path: 'elenco-interventi',
        component: InterventiComponent,
        children: [
          {
            path:'nuovo-intervento',
            component: NuovoInterventoComponent
          }
        ]
      },
    ]
  }
]

AppComponent中,我只有一个<div>,其中包含<router-outlet>,并且组件InterventiComponent已正确加载到地址/elenco-interventi。然后,我希望子NuovoInterventoComponent在地址/elenco-interventi/nuovo-intervento处找到,它必须完全替换父组件的内容。
如何重新使用父级中的<router-outlet>,以便可以替换父级页面的整个内容,并重新加载父级页面,并且如果我返回路由,还可以隐藏/不显示子级组件的内容? br /> 示例:

<div>
 <!--parent content-->
  <router-outlet></router-outlet> ==> when routing to children, just show children content
    and not children+parent content as I do now
</div>

0 个答案:

没有答案