Double Encoding of Query Parameters #2483
-
Reproductionhttps://stackblitz.com/edit/vitejs-vite-qjvsopux Steps to reproduce the bugDescriptionWhen pushing a query using the ExampleConsider the following code snippet: const router = useRouter();
router.push({
query: { notEncoded: '{name}', encoded: encodeURIComponent('{name}') },
}); The resulting URL appears as:
For reference, the expected single encoding result is: console.log(encodeURIComponent('{name}')); // %7Bname%7D But in the URL, it appears as ReproductionYou can reproduce this issue using the following Stackblitz project. Expected behavior/?notEncoded={name}&encoded=%7Bname%7D Actual behavior/?notEncoded={name}&encoded=%257Bname%257D Additional informationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
After reviewing the code, it appears that the behavior is intentional: router/packages/router/src/encoding.ts Lines 88 to 101 in 8e38733 Issue Description: I am encountering a problem with query string keys that are stringified objects. For example, consider the following URL:
When sharing this link or opening it from a terminal, the link transforms to:
The double quotes
This is an encoded version of the previously transformed URL, leading to a broken link. Concern: It seems that the encoded values are being replaced back to their unencoded forms, causing issues when sharing URLs. It would be beneficial to maintain the values in a URI-safe encoded format to prevent such problems. btw all works great with qs package import qs from 'qs'
createRouter({
// other options...
parseQuery: qs.parse,
stringifyQuery: qs.stringify,
}) |
Beta Was this translation helpful? Give feedback.
-
You must pass |
Beta Was this translation helpful? Give feedback.
You must pass
params
,query
, andhash
unencoded because the router handles them. If you follow that rule, it will work out