diff --git a/.changeset/loud-numbers-notice.md b/.changeset/loud-numbers-notice.md new file mode 100644 index 0000000000..ce4e9d8d1a --- /dev/null +++ b/.changeset/loud-numbers-notice.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Generates missing popstate events for Firefox when navigating to hash targets on the same page. diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index b1d30558be..9d7e39e5e1 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -205,7 +205,12 @@ const moveToLocation = ( history.scrollRestoration = 'auto'; const savedState = history.state; location.href = to.href; // this kills the history state on Firefox - history.state || replaceState(savedState, ''); // this restores the history state + if (!history.state) { + replaceState(savedState, ''); // this restores the history state + if (intraPage){ + window.dispatchEvent(new PopStateEvent('popstate' )); + } + } } else { if (!scrolledToTop) { scrollTo({ left: 0, top: 0, behavior: 'instant' });