Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve-scroll with buttons using inertia js

Working

<Link :href="route('products')" preserve-scroll>Products</Link>

Not Working

<form @submit.prevent="submit">
   ...
   <button type="submit" preserve-scroll>Submit</button>
</form>

package.json

...
"dependencies": {
    "@inertiajs/inertia": "^0.10.1",
    "@inertiajs/inertia-vue3": "^0.5.2",
    "@inertiajs/progress": "^0.2.6",
    "vue": "^3.2.20"
}
...

I haven't found a way in the inertia documentation to preserve scrolling when clicking on buttons, did someone face it yet?

like image 593
zarpio Avatar asked Oct 23 '25 07:10

zarpio


1 Answers

You need to tell the request you're making at the submit method to preserverScroll. Something like this:

submit () {
   this.$inertia.post(url, data, {
      preserveScroll: true
   })
}

And you can remove the preserve-scroll from the button. That is useless.

like image 136
Matheus Dal'Pizzol Avatar answered Oct 25 '25 10:10

Matheus Dal'Pizzol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!