make it work on nav
This commit is contained in:
parent
4276d45ee9
commit
00d3b41c9f
|
|
@ -134,13 +134,14 @@ export function useAnchor(id: AnchorID, onReveal: () => void) {
|
||||||
|
|
||||||
const listener = () => {
|
const listener = () => {
|
||||||
const params = new URLSearchParams(window.location.hash.slice(1));
|
const params = new URLSearchParams(window.location.hash.slice(1));
|
||||||
if (!params.has('anchor'))
|
if (params.has('anchor') && matchesAnchor(id, params.get('anchor')!))
|
||||||
return;
|
|
||||||
const anchor = params.get('anchor');
|
|
||||||
if (matchesAnchor(id, anchor!))
|
|
||||||
onReveal();
|
onReveal();
|
||||||
};
|
};
|
||||||
window.addEventListener('popstate', listener);
|
window.addEventListener('popstate', listener);
|
||||||
|
|
||||||
|
// check if we're already on the anchor. required to make it work on page load.
|
||||||
|
listener();
|
||||||
|
|
||||||
return () => window.removeEventListener('popstate', listener);
|
return () => window.removeEventListener('popstate', listener);
|
||||||
}, [id, onReveal]);
|
}, [id, onReveal]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue