inertia icon indicating copy to clipboard operation
inertia copied to clipboard

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

Open anchan42 opened this issue 1 year ago • 3 comments

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='.

anchan42 avatar Jan 25 '24 13:01 anchan42

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.

craigrileyuk avatar Jan 27 '24 15:01 craigrileyuk

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 🥴

anchan42 avatar Jan 28 '24 15:01 anchan42

router.get('/', {
    sizes:value
},{
    preserveState: true
})

Ilsaf-Zag avatar Feb 01 '24 11:02 Ilsaf-Zag

For the ones that would find it useful

router.visit(window.location.pathname)

if a full reset is intended.

  • use visit() or get() and window.location.pathname

MohamedLamineAllal avatar Apr 16 '24 23:04 MohamedLamineAllal

Thanks all, gonna close this one now.

driesvints avatar Apr 18 '24 09:04 driesvints