Skip to content

Commit 2a45d55

Browse files
committed
fix stale TOC navigation after route changes
1 parent 8bda87b commit 2a45d55

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎website/src/components/OnThisPage.tsrx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ export function OnThisPage(props: {
252252
const heading = document.getElementById(id);
253253
if (!heading) return;
254254
event.preventDefault();
255+
const pageUrl = location.pathname + location.search;
255256
const navigate = () => {
257+
const stillCurrent =
258+
location.pathname + location.search === pageUrl && document.getElementById(id) === heading;
259+
if (!stillCurrent) return;
256260
const reduce =
257261
typeof window.matchMedia === 'function' &&
258262
window.matchMedia('(prefers-reduced-motion: reduce)').matches;

0 commit comments

Comments
 (0)