Search code examples
angulartypescriptangular2-routingangular5angular4-router

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.


Solution

  • 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>