admin管理员组文章数量:1418361
I wanted to navigate to a URL using queryParams
while Routing in Angular.
<a routerLink='/master' [queryParams]="{query:'%US',mode:'text'}"><li (click)="search()">Search</li></a>
The URL I wanted to navigate is:
http://localhost:4200/master?query=%US&mode=text
But when I click on search it navigates me to:
http://localhost:4200/master?query=%25US&mode=text
I do not know why 25
is appended after the %
symbol. Can anyone tell me a cleaner way to navigate correctly.
I wanted to navigate to a URL using queryParams
while Routing in Angular.
<a routerLink='/master' [queryParams]="{query:'%US',mode:'text'}"><li (click)="search()">Search</li></a>
The URL I wanted to navigate is:
http://localhost:4200/master?query=%US&mode=text
But when I click on search it navigates me to:
http://localhost:4200/master?query=%25US&mode=text
I do not know why 25
is appended after the %
symbol. Can anyone tell me a cleaner way to navigate correctly.
-
It is working correctly.
%
is the escape character for URL encoding, so literal%
characters must be escaped, otherwise your URL is invalid. If this concept is new to you, read about it here. – Jonathan Hall Commented May 26, 2018 at 8:29 -
I tried using
\%
but it is also not working – Praveen Ojha Commented May 26, 2018 at 8:32 -
No. It is working.
%25
is correct. '\' is not an escape character in a URL. – Jonathan Hall Commented May 26, 2018 at 8:33 -
2
Please read what I have said, and follow that link. You are already using
%
correctly. – Jonathan Hall Commented May 26, 2018 at 8:36 - 1 if you wanna change url structure you can try angular url serializer stackoverflow./a/49618237/4399281 for your case may be it is: function cleanUrl(url) { return url.replace("%25",'%') } – Fateh Mohamed Commented May 26, 2018 at 12:41
1 Answer
Reset to default 3In URLs, the percent sign has special meaning and is used to encode special characters. For example, = is encoded as %3D.
Certain special characters are not allowed in url. If you want to use those in url you have to encode them using encodeURIComponent javascript function. %25 is actually encoded version of % character. Here browser is encoding them itself.
When trying to get queryParams from url , you can decode them using decodeURIComponent.
For more information check : https://support.microsoft./en-in/help/969869/certain-special-characters-are-not-allowed-in-the-url-entered-into-the
https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent
本文标签: javascriptIn URLis replaced by 25 when using queryParams while routing in AngularStack Overflow
版权声明:本文标题:javascript - In URL `%` is replaced by `%25` when using `queryParams` while routing in Angular - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745271120a2650897.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论