Reputation: 171
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.
Upvotes: 5
Views: 13681
Reputation: 11982
you can try:
<a [routerLink]="'/market/'+ currency" [queryParams]="{sidebar: 'home'}"></a>
or:
<a routerLink = "/market/{{currency}}" [queryParams]="{sidebar: 'home'}"></a>
Upvotes: 8
Reputation: 8176
There is no issue in your code. I tried following and its working nicely.
I have even added an extra parameter.
<a [routerLink]="['/market', currency]" [queryParams]="{sidebar:'home',tab:'5'}">Go to market</a>
TS :
const routes: Routes = [
{ path: "market/:currency", component: AppComponent}
];
I am getting following result :
Upvotes: 5
Reputation: 2851
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>
Upvotes: 11
Reputation: 3574
Try using:
<a [routerLink]="['/market', currency]" [queryParams]="{sidebar: home}"></a>
Upvotes: 1