Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

The page keeps its scroll position after a Next.js Link navigation

ErrorLink navigates but the new page opens scrolled down

Short answer

Next.js keeps the scroll position on purpose. It only scrolls to the new page when the top of that page is not visible. So a link inside a long page may leave you mid-scroll. Check for scroll={false}, a sticky header, and then add a small scrollTo on route change if you want always-top.

  • Applies to Next.js 15, Next.js 16, App Router
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Search the code for scroll options that switch scrolling off.

    grep -rnE "scroll=\{false\}|scroll: false" app components
  2. 2Match what you see, then jump to its fix

    1. 1Navigation never scrolls, from that one link onlyscroll is set to false on the Link or on router.pushFix
    2. 2The page scrolls, but content starts hidden under the headerThe first element of the new page is a sticky or fixed headerFix
    3. 3Works from the top of a page but not from a long page whose first element stays in viewThe new page is already visible, so Next.js leaves the scroll aloneFix

What does the error look like?

  • Link navigates but the new page opens scrolled down
  • New page content hidden behind a sticky header after navigation

Cause 1 of 3

scroll is set to false on the Link or on router.push

1Check

The scroll prop on Link, or scroll: false on router.push and router.replace, tells Next.js not to manage scroll.

grep -rnE "scroll=\{false\}|scroll: false" app components

2Fix

Remove it, or set it to true.

<Link href="/dashboard">Dashboard</Link>

router.push('/dashboard') // no scroll option

3Verify

Click the link from the middle of a long page.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

The first element of the new page is a sticky or fixed header

1Check

The Link docs say Next.js skips sticky and fixed elements when it looks for the scroll target, so content can end up behind a sticky header.

grep -rnE "sticky|fixed" app/layout.tsx app/globals.css

2Fix

Offset the scroll with scroll-padding-top equal to the header height.

/* app/globals.css */
html {
  scroll-padding-top: 64px; /* header height */
}

3Verify

Navigate again; the heading should sit below the header.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

The new page is already visible, so Next.js leaves the scroll alone

1Check

By design the default is to maintain the scroll position. Next.js scrolls to the top of the first page element only when that page is not visible in the viewport.

grep -rn "export default function" app/template.tsx app/layout.tsx 2>/dev/null

2Fix

If you always want the top, scroll in a small client component placed in the layout and keyed on the pathname.

// app/scroll-top.tsx
'use client'
import { useEffect } from 'react'
import { usePathname } from 'next/navigation'

export function ScrollTop() {
  const pathname = usePathname()
  useEffect(() => {
    window.scrollTo({ top: 0, left: 0, behavior: 'instant' })
  }, [pathname])
  return null
}

3Verify

Click between two long pages; each should open at the top.

npm run dev

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Treat scroll={false} as an exception, and comment why it is there.
  • Set scroll-padding-top as soon as a layout has a sticky header.
  • Test navigation from the bottom of a long page, not only from the top.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.