简体   繁体   English

Angular 4中的路由-嵌套子代

[英]Routing in Angular 4 - Nested Children

I am trying to implement multiple levels of nested children and was wondering if someone would be able to help. 我正在尝试实现多个级别的嵌套孩子,并且想知道是否有人能够提供帮助。 The issue I am having at the moment is that when I have a nested child route it needs to contains another <router-outlet> and therefore two screens appear on one page. 我目前遇到的问题是,当我有一个嵌套子路由时,它需要包含另一个<router-outlet> ,因此一页上会出现两个屏幕。

Code

app-routing 应用路由

  { path: 'claim/:id', component: ClaimDashboardComponent, data: { breadcrumb: 'Claim' }, children: [
    { path: 'details', component: ClaimDetailsComponent, data: { breadcrumb: 'Details' } }
  ]}

Now as you can see when the user hits the URL for example claim/1 then the ClaimDashboardComponent will load. 现在您可以看到,当用户点击例如ClaimDashboardComponent claim/1的URL时,将会加载ClaimDashboardComponent I then want to be able to click on a box inside the Component which will then load the details for that claim. 然后,我希望能够单击Component内部的一个框,然后将加载该声明的详细信息。

The issue i seem to be having is that I have to add a <router-outlet> to the ClaimDashboardComponent so when i load the URL claim/1/details both components seem to be appearing. 我似乎遇到的问题是,我必须向ClaimDashboardComponent添加<router-outlet> ,所以当我加载URL ClaimDashboardComponent claim/1/details两个组件似乎都出现了。

I just want the ClaimDetailsComponent to load and the ClaimDashboardComponent HTML to be removed. 我只希望ClaimDetailsComponent加载并删除ClaimDashboardComponent HTML。

{ path: 'claim/:id' children:[
    {path:'', component: ClaimDashboardComponent, 
                  data: { breadcrumb: 'Claim' }},
    { path: 'details', component: ClaimDetailsComponent, 
                  data: { breadcrumb:'Details' } }
  ]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM