[英]passing multiple parameters to routerLink
I want to use routerLink to navigate to another component , here is my route definition我想使用 routerLink 导航到另一个组件,这是我的路由定义
{path: 'articles/:id/edit-translation/:translation_id',component: ArticleEditTranslationComponent}
what is the correct format to pass theses 2 params (id,translation_id) to routerLink ?将这两个参数(id,translation_id)传递给 routerLink 的正确格式是什么?
Let's say id
is 1 and translation_id
is 2. Then you could use it like bellow example假设
id
是 1, translation_id
是 2。那么你可以像下面的例子一样使用它
<a [routerLink]="['/articles/1/edit-translation/2']">
link to component
</a>
Also if you need to use id
and translation_id
as variables in the component此外,如果您需要在组件中使用
id
和translation_id
作为变量
in component在组件中
id = 1;
translation_id = 2;
in component template you could use like this : Refer the DOC for more details在组件模板中,您可以像这样使用:有关更多详细信息,请参阅DOC
<a [routerLink]="['/articles', id, 'edit-translation', translation_id]">
link to component
</a>
or like bellow way或者像下面这样
<a [routerLink]="['/articles/'+ id +'/edit-translation/'+ translation_id]">
link to component
</a>
<a [routerLink]="['/articles', id, 'edit-translation', translation_id]"> link to another component</a>
更多参考, https://angular.io/api/router/RouterLink和https://angular.io/guide/router
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.