Use history.pushState for hash link navigation in techdocs
This commit is contained in:
committed by
Himanshu Mishra
parent
bd5eb8df59
commit
99a778ac9f
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs': patch
|
||||
---
|
||||
|
||||
Use `history.pushState` for hash link navigation.
|
||||
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user