Skip to content

Commit f92a297

Browse files
committed
fixed missing hash
1 parent dd4c37e commit f92a297

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lib_components/components/NeonPage/NeonPage.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,6 @@ const NeonPage = (props) => {
422422
if (sidebarLinks.length === 5) {
423423
return sidebarLinks[3].hash;
424424
}
425-
if (sidebarLinks.length === 7) {
426-
return sidebarLinks[1].hash;
427-
}
428425
return '#';
429426
})();
430427
const currentSidebarHash = initialCurrentSidebarHash;
@@ -438,7 +435,19 @@ const NeonPage = (props) => {
438435
const headerOffset = (headerRef.current || {}).offsetHeight || 0;
439436
const stickyOffset = belowMd ? (sidebarRef.current || {}).offsetHeight || 0 : 0;
440437
if (hash === '#') { return 0; }
441-
const anchor = contentRef.current.querySelector(hash);
438+
let selector = null;
439+
try {
440+
const url = new URL(hash, window.location.origin);
441+
selector = url.hash;
442+
} catch {
443+
if (hash.startsWith('#')) {
444+
selector = hash;
445+
}
446+
}
447+
if (!selector) {
448+
return -1;
449+
}
450+
const anchor = contentRef.current.querySelector(selector);
442451
return !anchor ? -1 : anchor.offsetTop + headerOffset - stickyOffset - Theme.spacing(5);
443452
}, [hasSidebarLinks, sidebarLinksAsStandaloneChildren, belowMd]);
444453

0 commit comments

Comments
 (0)