【问题标题】:Angular 2 - Routing- Showing different route name in the browser address barAngular 2 - 路由 - 在浏览器地址栏中显示不同的路由名称
【发布时间】:2017-07-17 10:08:14
【问题描述】:

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

{
 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。是否可以在“animals/cat”的地址栏中只显示“cat”,在“animals/dog”路由的地址栏中只显示“dog”。

【问题讨论】:

标签: angular angular2-routing


【解决方案1】:

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

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

angular 会自动将孩子链接到最近的祖先(如果没有的话,也可以是根)

【讨论】:

  • 谢谢。我在哪里可以找到有关此的文档。
  • 在他们的官方文档中有一个很长的部分解释了 Angular 路由器的工作原理:angular.io/guide/router 对于您的具体情况,您可以查看名为“无组件路由”的部分,其中有一个示例和你的很相似。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
  • 2018-09-08
  • 1970-01-01
相关资源
最近更新 更多