gpt4 book ai didi

javascript - Angular 2 : Create route in the controller/component

转载 作者:行者123 更新时间:2023-11-28 05:48:53 24 4
gpt4 key购买 nike

在我的路线配置中,我设置了一 strip 有子项的路线,如下所示:

 {
path: 'users',
children: [
{ path: ':id', component: UserDetailsComponent },
{ path: '', component: UserListComponent }
]
}

现在,在我的 UserListComponent 中,我需要动态构建一个指向用户配置文件的链接,其中包含路径和 id 值...那么,如果我已成功注入(inject)路由器(专用路由器),我将如何做到这一点:路由器)

所以我想做的是

const link = this.router.createUrl('/users', {id:item.id});

我会得到这样的东西

/用户/xyse1334

最佳答案

对于路由参数,只需像路径元素一样传递它们

const link = '/users/${item.id}';

关于javascript - Angular 2 : Create route in the controller/component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38250813/

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