diff --git a/app/components/Navbar.tsx b/app/components/Navbar.tsx index 1891b2e..ac15dac 100644 --- a/app/components/Navbar.tsx +++ b/app/components/Navbar.tsx @@ -170,10 +170,25 @@ export function Navbar() { // whenever pathname becomes "/" (covers both the initial load and a // client-side transition landing here), a short delay lets layout // settle first. + // + // The no-hash branch below matters just as much: since the Navbar lives + // in the root layout (never unmounts across navigations), Next.js's + // default Link scroll behavior treats "/" as already-visible and leaves + // the current scrollY untouched instead of resetting to top (see + // next/dist/docs .../link.md's "maintain scroll position" default). + // Landing on Home from a page scrolled halfway down (e.g. clicking the + // logo from a scrolled /shop) then visually "lands" wherever that old + // offset happens to fall in Home's layout — often right around the + // Werkzeuge section — instead of at the top. Forcing scrollTo(0, 0) here + // makes a plain logo/Home navigation always start at the top, exactly + // like the same-page click handler below already does. useEffect(() => { if (pathname !== "/") return; const hash = window.location.hash.slice(1); - if (!anchorIds.includes(hash)) return; + if (!anchorIds.includes(hash)) { + window.scrollTo(0, 0); + return; + } const timer = setTimeout(() => { const el = document.getElementById(hash); if (el) {