Skip to content

Commit 272d70a

Browse files
committed
Auto-scroll on page load for internal page links
1 parent e889610 commit 272d70a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/react_components/Anchor.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import useBrokenLinks from "@docusaurus/useBrokenLinks";
22
import {useLocation} from "@docusaurus/router";
3+
import { useEffect } from 'react';
34

45

56
export function Anchor({
@@ -30,6 +31,12 @@ export function Anchor({
3031
// https://github.com/vercel/next.js/issues/51346. The workarounds there are
3132
// for next.js, not plain React. It may have something to do with `pushState`
3233
if ( do_highlight && hash === "#" + id ) {
34+
35+
useEffect(()=>{
36+
const this_element = document.getElementById( id );
37+
this_element.scrollIntoView();
38+
}, []);
39+
3340
return (
3441
<mark
3542
id={ id }

0 commit comments

Comments
 (0)