inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.3k stars 423 forks source link

router.reload would not remove query string when it got removed from the data option. #1779

Closed anchan42 closed 5 months ago

anchan42 commented 8 months ago

Version:

"@inertiajs/vue3": "^1.0.14"

Describe the problem:

When the property of the data option object is removed, reload will not remove the corresponding query string from the URL. The query string would be the last value before the removal.

Steps to reproduce:

router.reload({ data:{search:'gold'} })

Would produce 'search=gold' query string

Reload the page again with:

router.reload({ data:{search:'wood'} })

Would produce 'search=wood' query string. This is expected.

But again with:

`router.reload({ data:{} })

The query string would remain 'search=wood'.

However this: router.reload({ data:{search:null} })

or router.reload({ data:{search:''} })

Would produce 'search='.

craigrileyuk commented 8 months ago

This is expected behaviour. It's reloading the page you're on with the given query string. Nothing is changed unless told otherwise.

If you want to work with a blank slate, use a manual router.get instead.

anchan42 commented 8 months ago

I tried that but all the props got reloaded and caused the backend to re-evaluate all of them.
I do understand that can be an expected behaviour. As the name suggested reload could be understood as hitting the same URL with nothing changed.

However, we can update and add to the query string or even set them to blank but can't remove them. Can't help feeling that something is missing.

I will have to make do with blank query strings, I suppose. It is not the end of the world, to be honest. No users would probably notice. The ugly URL would just bug me everytime I look at it though 🥴

Ilsaf-Zag commented 8 months ago
router.get('/', {
    sizes:value
},{
    preserveState: true
})
MohamedLamineAllal commented 5 months ago

For the ones that would find it useful

router.visit(window.location.pathname)

if a full reset is intended.

driesvints commented 5 months ago

Thanks all, gonna close this one now.