Skip to content

Commit

Permalink
Scroll to top on SPA link navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
nf-s committed Oct 16, 2024
1 parent 8d823c5 commit 49d5aa5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const Link: React.FC<LinkProps> = ({ children, href, className }) => {
className={"text-blue-500 underline " + (className ?? "")}
href={href}
target={!href?.startsWith("/#") ? "_blank" : undefined}
onClick={() => {
// Scroll to top on SPA navigation
if (href?.startsWith("/#/")) {
window.scrollTo(0, 0);
}
}}
rel="noreferrer"
>
{children}
Expand Down

0 comments on commit 49d5aa5

Please sign in to comment.