Skip to content

Commit

Permalink
feat: modify docs postmsg logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyunWan committed Nov 21, 2024
1 parent 35bebe9 commit ed80b97
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions docs/docusaurus/src/theme/DocSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,24 @@ export default function DocSidebarWrapper(props: Props): JSX.Element {

useEffect(() => {

const sendPostMsg = (path: string) => {
window.parent.postMessage({ path }, "*");
const sendPostMsg = () => {
window.parent.postMessage({ path: window.location.pathname }, "*");
};

sendPostMsg(window.location.pathname);
const sendPostHashMsg = () => {
window.parent.postMessage({ path: window.location.pathname + window.location.hash }, "*");
}

window.addEventListener("click", sendPostMsg);
window.addEventListener("hashchange", sendPostHashMsg);

sendPostMsg();

return () => {
window.removeEventListener('click', sendPostMsg);
window.removeEventListener('hashchange', sendPostHashMsg);
}

window.addEventListener("click", () => {
sendPostMsg(window.location.pathname);
});
window.addEventListener("hashchange", () => {
sendPostMsg(window.location.pathname + window.location.hash);
});
}, []);


Expand Down

0 comments on commit ed80b97

Please sign in to comment.