Angular 2:让子路由组件替换路由器插座中的Parent

时间:2017-03-16 18:20:27

标签: angular

有没有办法在父路线的folder <-"C:\\\\Users\\USER\\Desktop\\LABWORK\\ECGV0007_everyRRQTinputIntoEntropy_csv" file_list <- list.files(path=folder, pattern="*.csv") for (i in 1:length(file_list)){ assign(file_list[i], x <-read.csv(paste(folder, file_list[i], sep=" ", fill=TRUE, colClasses=c('null', 'numeric', rep('null',6)))), y <-read.csv(paste(folder, file_list[i], sep=" ",fill=TRUE, colClasses=c(rep('null',2), 'numeric', rep('null',5)))) )}

中显示子路线

例如,假设我们有两条路线:

<router-outlet>

我需要第二个孩子成为第一个孩子,但我还需要用/users/12345 /users/12345/orders/12345 的内容完全替换/users/12345的内容,而/users/12345/orders/12345的内容与/users/12345/orders/12345相对{1}} sub /users/12345

我以为我可以通过命名父级路由器来实现这一点,并且两条路由都以它为目标,但是从我一直在做的研究(以及它引起的错误)我感觉这些名称是为了已存在主路由器插座时的二次使用

5 个答案:

答案 0 :(得分:14)

我有同样的问题。这就是我修复它的方法:

const routes: Routes = [
   {
    path: '',
    children: [
         {
           path: '',
           component: ParentComponent,
         },
         {
           path: 'child',
           component: ChildComponent,
         }
     ]
   }
];  

答案 1 :(得分:12)

你可以通过设置这样的路线来实现:

const routes : Routes = [
  { 
    path : 'user/:id',
    component : ParentComponent,
    children : [
      { path : '', component : UserComponent },
      { path : 'order/:id', component : OrderComponent }
    ]
  }
]

ParentComponent的模板只有<router-outlet>来加载其子代。

答案 2 :(得分:4)

如果您需要根据子路由处于活动状态来隐藏某些内容(例如数据网格或指令面板),则可以简单地使用以下方法:

<div *ngIf="outlet.isActivated == false">
   Please select a child route!
</div>

<router-outlet #outlet="outlet"></router-outlet>

#outlet="outlet"中加上引号很重要,因为您正在导出模板变量引用。

router-outlet上还有一些用于激活和停用的事件。

一种替代方法是在发生NavigationEnd事件时get the child route,然后决定要显示或隐藏的内容。对于较简单的情况,第一种方法应该可以正常工作。

我认为与您的问题也不相关,但是您可以像其他操作一样完全隐藏router-outlet*ngIf

答案 3 :(得分:3)

编辑:我已经提出了一个新的解决方案,围绕使用模板指令,允许设置层次上相对于同一级别的路由。

示例代码/演示可在此处找到:https://stackblitz.com/edit/angular-routing-page-layout

答案 4 :(得分:2)

 let routes = [
  { 
    path: 'users/:id',
    component: UsersComponent
  },
  {
    path: 'users/:id/orders/:id',
    component: OrdersComponent
  }
 ];
相关问题