Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Swaz's avatar
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.

0 likes
7 replies
gych's avatar

The browser will always encode it, URL's can only be used with ASCII characters

1 like
Swaz's avatar
Level 20

@gych Is this something new? I had brackets by default a couple months ago. I updated to the latest versions of Laravel, Inertia, vue, vite, etc... and now they are encoded. That's why I am trying to get them back, looked much cleaner before.

Snapey's avatar

Shouldn't your url be

https://example.test/?foo=[1,2]

Pretty sure Laravel will decode the encoded symbols anyway?

Swaz's avatar
Level 20

@Snapey I've never seen that format before, but I have seen ?foo=1,2,3. Even cleaner than the brackets.

I know laravel will decode no problem, I'm trying to do this purely for aesthetics.

gych's avatar

@Swaz I personally use this approach and in the browser it will display as ?foo=1%2C2%2C3%2C

The , will get converted to %2C

orphanedrecord's avatar

Hey @swaz I'm facing a similar issue just saw this in a inertiajs/inertia-laravel (GitHub Issue), but haven't tried it yet as I need to update my version of Inertia.

Anyway, maybe that helps?

Please see the URL Readability with InertiaJS Issue for details.

# Per pascalbaljet, as of v2.0.3, you may now use a custom URL resolver that decodes the URL:

Inertia::resolveUrlUsing(function (Request $request) {
    return Str::start(Str::after(rawurldecode($request->fullUrl()), $request->getSchemeAndHttpHost()), '/');
});

Please or to participate in this conversation.