Use history.pushState for hash link navigation in techdocs

This commit is contained in:
Kevin Lee
2021-01-12 12:45:10 -08:00
committed by Himanshu Mishra
parent bd5eb8df59
commit 99a778ac9f
2 changed files with 14 additions and 1 deletions
@@ -115,7 +115,15 @@ export const Reader = ({ entityId, onReady }: Props) => {
baseUrl: window.location.origin,
onClick: (_: MouseEvent, url: string) => {
const parsedUrl = new URL(url);
navigate(`${parsedUrl.pathname}${parsedUrl.hash}`);
if (parsedUrl.hash) {
history.pushState(
null,
'',
`${parsedUrl.pathname}${parsedUrl.hash}`,
);
} else {
navigate(parsedUrl.pathname);
}
shadowRoot?.querySelector(parsedUrl.hash)?.scrollIntoView();
},