0

routerLink with params is not working

<a routerLink="/post?id=1">
  Link
</a>

I want to navigate in other links with params using routerLink

3 Answers3

0

Use [queryParams] in adition to routerLink as explained in this post How to pass query parameters with a routerLink

hasnaas
  • 86
  • 5
0

you should use

<a [routerLink]="['/post']" [queryParams]="{ id: 1 }">View post</a>
Jondi
  • 431
  • 4
  • 8
0

In your particular example you'd do the following routerLink:

    <a [routerLink]="['/post']" [queryParams]="{id: '1'}" queryParamsHandling="preserve"> Link
</a>

id can be variable as well.

Nirmalya Roy
  • 623
  • 4
  • 8