-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8c707b
commit 17760ee
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/components/src/templates/next/components/internal/ScrollToTop.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client" | ||
|
||
import { useEffect } from "react" | ||
import { usePathname } from "next/navigation" | ||
|
||
/* | ||
Fix with issue w/ "next/Link" not scrolling to the top when clicking on <Link /> | ||
if we have a header with "sticky" that's not in its sticky position. | ||
Ref: https://github.com/vercel/next.js/issues/45187#issuecomment-1639518030 | ||
*/ | ||
export const ScrollToTop = () => { | ||
const pathname = usePathname() | ||
|
||
useEffect(() => { | ||
// Required because "window" is a browser-only API that's not available | ||
// during static site generation (SSG) | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (window) window.scroll(0, 0) | ||
}, [pathname]) | ||
|
||
return <></> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters