角度 2 - 路由 - 在浏览器地址栏中显示不同的路由名称



是否可以在地址栏中显示角度 2 和 4 中特定路由的州名称。 例如,我有以下路由配置,

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

当地址为"animals/cat"时,它会在 AnimalComponent 路由器出口中加载 CatComponent,当地址为"animals/dog"时,它会在 AnimalComponent 路由器出口中加载 DogComponent。是否可以在"动物/猫"的地址栏中仅显示"猫",在"动物/狗"路线的地址栏中显示"狗"。

当然,只需从父路由中删除路径:

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

Angular 会自动将子项链接到最近的祖先(如果没有,则链接到根(

最新更新