keepScrollPosition
Environment: client
Type: boolean | string | string[] | ((pageContext: PageContextClient) => boolean | string | string[])
Default value: false
The keepScrollPosition
setting enables you to control whether the page scrolls to the top upon navigation.
It's commonly used for nested layouts such as tabs, see API > <Layout>
> Nested layouts.
For a control on a link-by-link basis, see <a href="/some-url" keep-scroll-position />
.
Basics
By default, the page is scrolled to the top upon navigation. But if you set keepScrollPosition
to true
then the page's scroll position is preserved instead.
pages/product/@id/+config.js
pages/product/@id/pricing/+Page.js
pages/product/@id/reviews/+Page.js
Note that the scroll isn't preserved (the page scrolls to the top) if the @id
parameter differs.
See Advanced if this behavior doesn't fit your use case.
Advanced
You can preserve the scroll position between any arbitrary group of pages (the "scroll group").
If two URLs belong to the same scroll group, then the scroll position is preserved.
You can also programmatically set the scroll group: