gpt4 book ai didi

Angular2 - 如何使用带有动态 url 的路由器

转载 作者:太空狗 更新时间:2023-10-29 17:22:13 27 4
gpt4 key购买 nike

假设我有这个嵌套的 itemListComponent,它是 rootComponent 的子组件,使用以下模板:

<span *ngFor="#item of list">
<a [routerLink]="[item.url]">{{item.title}}</a> |
</span>

从 Json 服务提供的路径 item.url 可以具有以下路径结构之一:

  • /category1/(a content id)/(a title connected with dashion(-))
  • /category2/(a content id)/(a title connected with dashion(-))
  • /category3/(a content id)/(a title connected with dashion(-))

例子:

category2/987654/hello-world
category2/123456/hi-teacher
category3/554433/yo-brother

如何实现 @RouteConfig 以便这些链接使用 itemDetail 组件?

抱歉,如果这看起来不是很详细。对于由具有完整路径(非组合路径)的服务提供的路由 URL,我没有找到明确的操作指南

最佳答案

试试这个:

<span *ngFor="#item of list">
<a [routerLink]="['/category', item.url]">
{{item.title}}
</a>
</span>

路线.ts:

{path: "category/:id", component: CategoryComponent}

关于Angular2 - 如何使用带有动态 url 的路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36207023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com