简体   繁体   中英

passing multiple parameters to routerLink

I want to use routerLink to navigate to another component , here is my route definition

{path: 'articles/:id/edit-translation/:translation_id',component: ArticleEditTranslationComponent}

what is the correct format to pass theses 2 params (id,translation_id) to routerLink ?

Let's say id is 1 and translation_id is 2. Then you could use it like bellow example

  <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

in component

  id = 1;
  translation_id = 2;

in component template you could use like this : Refer the DOC for more details

<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/RouterLinkhttps://angular.io/guide/router

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM