The browser will always encode it, URL's can only be used with ASCII characters
Apr 8, 2024
7
Level 20
Prevent query params from being encoded in Inertia
I have a form that submits a get request to filter some data. The form has array values. I want the array values to be brackets in the url, but they are getting encoded.
Expected
'https://example.test/?foo[]=1&foo[]=2'
Result
'https://example.test/?foo%5B0%5D=1&foo%5B1%5D=2'
I've tried using axios.interceptors, but it's still being encoded.
import qs from 'qs'
import axios from 'axios'
axios.interceptors.request.use(
function (config) {
let url = new URL(config.url)
url.search = qs.stringify(qs.parse(url.search), {
arrayFormat: 'brackets', encode: false
})
config.url = url.href
// console.log(config.url) = https://example.test/?foo[]=1&foo[]=2
return config
}
);
At this point I have no idea what is encoding the url.
Is it a chrome thing, a vite thing, axios, inertia?
Any help would be great.
Please or to participate in this conversation.