简体   繁体   中英

queryParams in Angular 2 being encoded, how do I prevent this from happening?

I have a link in Angular 2 which looks like this:

<a routerLink="/summary" queryParams="x=1">Ref. ID</a>

I expect this to resolve to

summary?x=1

Instead it resolves to:

/summary?0=x&1=%3D&2=1

Which is not what I want at all.

Whenever I inject ActivatedRouteSnapshot into a component and take a look at the queryParams property, it is an object containing 3 strings, one for each character:

截图

Obviously I am missing something obvious, could somebody point me in the right direction? Cheers

根据RouterLink指令,您必须将其设置如下:

<a [routerLink]="['/summary']" [queryParams]="{x:1}">Ref. ID</a>

You have to use binding [] for the queryParams

<a routerLink="/summary" [queryParams]="{x : 1}">Ref. ID</a>

That will probably work better :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM