2017-05-08 34 views
2

我有有這個HTML一般Artists組件:Angular中的默認出口路線值?

<div tyle="float:left;width:40%;border:solid 1px gray;"> 
    <router-outlet name="left"></router-outlet> 
</div> 

<div style="float:right;width:40%;border:solid 1px orange;"> 
    <router-outlet name="right"></router-outlet> 
</div> 

窗格中應包含藝術家列表
窗格中應包含藝術家細節

這裏路線定義:

const routes: Routes = [ 
    { 
    path: 'artists', 
    component:ArtistsComponent , 
     children: [ 
      { 
       path: 'list', 
       outlet: 'left', 
       component: ArtistListComponent 
      } , 
      { 
       path: ':id', 
       outlet: 'right', 
       component: ArtistDetailsComponent 
      } 
     ] 
} 
, 
    { 
    path: '', 
     pathMatch:'full' , 
    redirectTo: '/artists', 
    } 
] 

所以當應用到了,這是我看到

網址:http://localhost:4200/artists

enter image description here

如果我想看到這兩個左窗格中,右窗格中我應該定位到:

網址:http://localhost:4200/artists/(left:list//right:2)

enter image description here

問:

我怎樣才能聲明默認出口路由值?

喜歡的東西:

... 
{ 
    default:'list', 
    path: 'list', 
    outlet: 'left', 
    component: ArtistListComponent 
} , 
{ 
    default:'1', 
    path: ':id', 
    outlet: 'right', 
    component: ArtistDetailsComponent 
} 

NB

我知道我也可以把應用程序(在啓動時)直行至 http://localhost:4200/artists/(left:list//right:2),但我不知道如果我能在網點指定默認值config本身

+0

我會使用實際鏈接或重定向生成的默認選項。在導航組件中,我會設置默認值。因此,除非您單擊或執行了*特定操作*,否則要發送的參數是默認參數。 – SrAxi

回答

1

使用redirectTo與空路徑:

const routes: Routes = [ 
{ 
    path: 'artists', 
    component:ArtistsComponent , 
    children: [ 
     { 
     path: '', 
     pathMatch: 'full', 
     redirectTo: 'artists/(left:list)' 
     }, 
     { 
      path: 'list', 
      outlet: 'left', 
      component: ArtistListComponent 
     } , 
     { 
      path: ':id', 
      outlet: 'right', 
      component: ArtistDetailsComponent 
     } 
    ] 

}