Ammar M Mashfj
Ammar M Mashfj

Reputation: 104

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 ?

Upvotes: 0

Views: 3123

Answers (2)

coder
coder

Reputation: 8702

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>

Upvotes: 2

Ved
Ved

Reputation: 746

<a [routerLink]="['/articles', id, 'edit-translation', translation_id]"> link to another component</a>

For more reference, https://angular.io/api/router/RouterLink and https://angular.io/guide/router

Upvotes: 3

Related Questions