19

I'm trying to pass an id in my routerLink, how could I concatenate it?

<a routerLink="['/details', {{data.id}}]"> </a> doesnt work.

Do you have solutions?

Thanks in advance

3 Answers3

35

There you go.

<a [routerLink]="['/details', data.id]"> Link </a>
Roy
  • 7,811
  • 4
  • 24
  • 47
Oen44
  • 3,156
  • 1
  • 22
  • 31
  • 1
    Technically this works but the recommended way is to pass it as the second argument. Please take a look at Aragom's answer. – James Poulose Nov 28 '18 at 16:19
6

Parameters go as second item in the array syntax to router link, like this:

[routerLink]="['/details', data.id]

Read more here

Aragorn
  • 5,021
  • 5
  • 26
  • 37
1

Similar to above, but you can also do this:

<a [routerLink]="['/details' + data.id]"> Link </a>
Mike
  • 61
  • 1
  • 3