diff options
-rw-r--r-- | .changeset/loud-numbers-notice.md | 5 | ||||
-rw-r--r-- | packages/astro/src/transitions/router.ts | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/.changeset/loud-numbers-notice.md b/.changeset/loud-numbers-notice.md new file mode 100644 index 000000000..ce4e9d8d1 --- /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 b1d30558b..9d7e39e5e 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' }); |