Angular 2: Have Child Route Component Replace Parent in router-outlet

前端 未结 5 1666
猫巷女王i
猫巷女王i 2020-12-28 13:21

Is there a way to display a child route in the parent route\'s ?

For example, let\'s say we have two routes:

/users         


        
5条回答
  •  悲哀的现实
    2020-12-28 14:18

    You can do it by setting your routes like this :

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

    ParentComponent's template will have only the to load its children.

提交回复
热议问题