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

alex32's avatar
Level 2

Inertia preserveScroll | why is not working?

I'm using Breeze-React for Laravel 11, and I want the scroll position to remain unchanged when I click a button. According to the Inertia doc, this seems easy but it doesn't work for me. I don't want to create a new Hook given this functionality should already exist. When I click the button the scrollbar always reset to the top. There is a video on Laracast but it's for the <Link> tag. Thanks

My button:

<PrimaryButton  disabled={processing} onClick={showb}>Enable </PrimaryButton>

showb()

    const showb = (e) => {   
        e.preventDefault();  

        get(route('reg.getreg'), {   
            preserveScroll: false,      // tried false and true  
            onSuccess: () => { 
                // OK
            },
             
        });
    }

https://inertiajs.com/scroll-management

0 likes
7 replies
JussiMannisto's avatar

You're using router.get() wrong. options is the third paramater, after url and data. The correct usage in your case:

router.get(route('reg.getreg'), {}, {   
	preserveScroll: true, 
});

// Or using router.visit():
router.visit(route('reg.getreg'), {   
	preserveScroll: true, 
});
alex32's avatar
Level 2

@JussiMannisto Thanks for your help, I tried your code. Same problem.

Note that the original code that I posted from Breeze works fine get(route('reg.getreg') .. the only problem is that preserveScroll: true, doesn't work and the page keeps on scrolling to the top.

JussiMannisto's avatar

@alex32 My examples definitely work and preserve the scroll state.

the only problem is that preserveScroll: true, doesn't work and the page keeps on scrolling to the top.

That's because you're not setting the preserveScroll option. You're setting preserveScroll in the data object.

alex32's avatar
Level 2

@JussiMannisto yes, router.get() has 3 args , but get() has only 2, and it works. In your form what happen if you use only get() ? I bet preserveScroll still works. That's because the problem with page scroll is somewhere else.

JussiMannisto's avatar

@alex32 Which get function are you using? Is it the one from the useForm hook? Show the whole component.

Does the reg.getreg route return an Inertia response?

alex32's avatar
Level 2

Yes both. I'm using useForm hook (below), and I get an Inertia response from reg.getreg. The code is from Breeze-React and it works, it's just preserveScroll that doesn't work.

Sinnbeck's avatar

Could it be that it isn't the body that's scrolling? If so you need to set a scroll region on the correct element. It's in the docs

Please or to participate in this conversation.