i have a route like this dashboard/tour/2/269
, this component represents tour details, and inside that component there are some links which refer to similar tours, so when a user click one of those links i want to reload the component based on the new params like let's say this dashboard/tour/5/150
, i tried to use a direct [routerLink]
but it attach the new params to the old one to become like this dashboard/tour/2/269/tour/5/150
the route become invalid.
any suggestions please.
You're going to have to inject
ActivatedRoute
into your component. Your routes would have to be set like this:Then subscribe to the params:
Your routerLink would be:
Here, I have injected an instance of
ActivatedRoute
asroute
in my constructor.You would need to obtain each of you params that you have listed on your routing for your Dashboard component. In this example, my routing is simple
persons/:id
where I would get theid
fromhttp://localhost:3000/persons/1
. So if I had a router link to next person say[routerLink]="['/persons', 2]"
, this snippet of code would update and provide me anid
of2
.Based on your current illustration and question, this sounds like the solution your looking for.
StackBlitz Solution
https://stackblitz.com/edit/routing-params