🥳 Inertia.js v1.0 has been released!

Scroll management

Scroll resetting

When navigating between pages, Inertia mimics default browser behaviour by automatically resetting the scroll position of the document body (as well as any scroll regions you've defined) back to the top. In addition, Inertia keeps track of the scroll position of each page and automatically restores that scroll position as you navigate forward and back in history.

Scroll preservation

Sometimes it's desirable to prevent the default scroll resetting behavior when making visits. You can disable this behaviour using the preserveScroll option when manually making visits.

router.visit(url, { preserveScroll: true })

You can also lazily evaluate the preserveScroll option based on the server's response by providing a callback to the option.

router.post('/users', data, {
  preserveScroll: (page) => Object.keys(page.props.errors).length,

You can also preserve the scroll position when using Inertia links using the preserve-scroll attribute.

import { Link } from '@inertiajs/vue3'

<Link href="/" preserve-scroll>Home</Link>

Scroll regions

If your app doesn't use document body scrolling, but instead has scrollable elements (using the overflow CSS property), scroll resetting will not work. In these situations, you must tell Inertia which scrollable elements to manage by adding a scroll-region attribute to the element.

<div class="overflow-y-auto" scroll-region>
  <!-- Your page content -->