22

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

4
  • 1
    I guess you have tried to put code inside post? It's not showing. Update it please. Commented Nov 28, 2018 at 16:01
  • Code please..and concatenate id with what? path? Commented Nov 28, 2018 at 16:03
  • Sorry I forgot to put it between quotes Commented Nov 28, 2018 at 16:07
  • Remove the curly brackets ({{ }}) in what you have now. You just need data.id after the route name. That should work. Commented Nov 28, 2018 at 16:09

3 Answers 3

39

There you go.

<a [routerLink]="['/details', data.id]"> Link </a>
Sign up to request clarification or add additional context in comments.

1 Comment

Technically this works but the recommended way is to pass it as the second argument. Please take a look at Aragom's answer.
7

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

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

Read more here

Comments

1

Similar to above, but you can also do this:

<a [routerLink]="['/details' + data.id]"> Link </a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.