Skip to content

Commit 6972308

Browse files
committed
fix: Do replaceState() to preserve state on possible <a> hash navigation
1 parent 2a6b7fd commit 6972308

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/lib/core/LocationLite.svelte.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export class LocationLite implements Location {
4444
['popstate', 'hashchange'].forEach((event) => {
4545
cleanups.push(on(globalThis.window, event, () => {
4646
this.#innerState.url.href = globalThis.window?.location?.href;
47+
if (!globalThis.window?.history?.state) {
48+
// Potential <a> hash navigation. Preserve current state.
49+
this.#goTo(this.#innerState.url.href, true, this.#innerState.state);
50+
}
4751
this.#innerState.state = globalThis.window?.history?.state ?? this.#innerState.state;
4852
}));
4953
});

0 commit comments

Comments
 (0)