vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.91k stars 1.19k forks source link

router.replace(string-location) re-encodes an already encoded hash #2060

Closed sreuss closed 10 months ago

sreuss commented 10 months ago

Reproduction

https://jsfiddle.net/10q87pvg/

Steps to reproduce the bug

Calling router.replace('/#some%20hash') will lead to the fullPath /#some%2520hash. On the other hand, calling router.push('/#some%20hash') yields the original /#some%20hash.

Expected behavior

router.replace should behave like router.push and not re-encode the hash.

Actual behavior

router.replace re-encodes the hash for the fullPath resulting in a double encoding.

Additional information

This is particularly troublesome if you cannot use route.hash and have to rely on fullPath to extract the original value. For example, if the hash contains a mixture of search params encoding and URI encoding.

posva commented 10 months ago

As a workaround: router.push({ path: '/', hash: '#some hash', replace: true }). The fix for this one should be quite simple: the hash is not being decoded before transforming the replace into a push