简体   繁体   中英

Encoding Uri using Link of react router dom not working

I want to encode uri, using Link tag of react-router-dom but when I use javascript encodeURIComponent to encode uri it does not show encoded uri in address bar(url bar) though i see uri encoded when i hover.

<Link key={i}  to={encodeURIComponent(item.url)}> {item.text}</Link>  

Am I mising anything or uri is decoded inside react router dom.

The Link in react router dom decodes the uri while pushing it to history.
Anybody can read this issue in github and related issues Path is decoded in createLocation #505
https://github.com/ReactTraining/history/issues/505

I did workaround of this issue by double encoding the uri so that it is decoded once while pushing in history.
encodeURIComponent(encodeURIComponent(item.url))
till now I have not found any side effects of this....hope this helps anybody facing this issue.

chrome hide encodeUrl,只需将其复制到nodepad ++即可看到

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