Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 routerLink params & query params

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.

like image 700
Can Karakoyun Avatar asked Nov 29 '22 13:11

Can Karakoyun


1 Answers

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>
like image 164
CruelEngine Avatar answered Dec 06 '22 11:12

CruelEngine