Angular 2 routerLink params & query params

Bahri Can Karakoyun picture Bahri Can Karakoyun · May 16, 2018 · Viewed 9.5k times · Source

Here is my route:

{ path: 'market/:currency', component: MainlayoutComponent, canActivate: [AuthGuard]}

I want redirect to with query params like this:

market/btc?sidebar=home

<a [routerLink]="['/market', currency]" [queryParams]="{sidebar: 'home'}"></a>

But when i click its redirect market/btc

What's the problem.

Editing

This code works i have another bug but i solved.

Answer

CruelEngine picture CruelEngine · May 16, 2018

you just need to preserve your queryParams :

queryParamsHandling="preserve"

Add the above attribute/directive to your route :

<a [routerLink]="['/market', currency]" [queryParams]="{sidebar: 'home'}" queryParamsHandling="preserve"></a>