2017-07-17 33 views
0

是否可以在角度2和4中顯示特定路由的地址欄中的狀態名稱。例如,我有以下路由配置,Angular 2 - 路由 - 在瀏覽器地址欄中顯示不同的路由名稱

{ 
path:"animals", 
component : AnimalComponent, 
children:[{ 
    path:"cat", 
    component:CatComponent 
},{ 
    path:"dog", 
    component:DogComponent 
}] 
} 

當地址是「animals/cat」時,它在AnimalComponent router-outlet中加載CatComponent,當地址是「animals/dog」時,它加載AnimalComponent router-outlet中的DogComponent。是否可以在地址欄中爲「動物/狗」路線的「動物/貓」和「狗」在地址欄中僅顯示「貓」。

+0

聽起來你正在尋找對於像https://stackoverflow.com/questions/38644314/changing-the-page-title-using-the-angular-2-new-router/38652281?s=1|3.2069#38652281或只是設置標題'與其他一些數據。 –

+0

請參閱:[設置文檔標題](https://angular.io/guide/set-document-title) – pzaenger

回答

0

當然,單純從父路由刪除路徑:

{ 
path:"", 
component : AnimalComponent, 
children:[{ 
    path:"cat", 
    component:CatComponent 
},{ 
    path:"dog", 
    component:DogComponent 
}] 
} 

角(如果沒有任何根)將自動鏈接孩子到最近的祖先

+0

感謝您的支持。我在哪裏可以找到關於此的文檔。 – Ramadurgarao

+0

有一個很長的部分解釋了Angular router如何在他們的官方文檔中工作:https://angular.io/guide/router 對於具體的情況,您可以看看「無組件路由」一節,其中有一個非常類似於你的例子。 – Siro

相關問題