From 2a6b7fd3c35eef3140c8ad4bfd90f4ec5630426f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramirez=20Vargas=2C=20Jos=C3=A9=20Pablo?= Date: Sat, 6 Sep 2025 01:21:04 -0600 Subject: [PATCH 1/2] feat: Support the use of regular HTML anchor elements for hash routing universes --- src/lib/core/LocationLite.svelte.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/core/LocationLite.svelte.ts b/src/lib/core/LocationLite.svelte.ts index c7e3fc3..2f5cb1c 100644 --- a/src/lib/core/LocationLite.svelte.ts +++ b/src/lib/core/LocationLite.svelte.ts @@ -44,7 +44,7 @@ export class LocationLite implements Location { ['popstate', 'hashchange'].forEach((event) => { cleanups.push(on(globalThis.window, event, () => { this.#innerState.url.href = globalThis.window?.location?.href; - this.#innerState.state = globalThis.window?.history?.state; + this.#innerState.state = globalThis.window?.history?.state ?? this.#innerState.state; })); }); return () => { From 697230827915e77919ecf94139b400e02f8924e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramirez=20Vargas=2C=20Jos=C3=A9=20Pablo?= Date: Sat, 6 Sep 2025 22:11:06 -0600 Subject: [PATCH 2/2] fix: Do replaceState() to preserve state on possible hash navigation --- src/lib/core/LocationLite.svelte.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/core/LocationLite.svelte.ts b/src/lib/core/LocationLite.svelte.ts index 2f5cb1c..67436b8 100644 --- a/src/lib/core/LocationLite.svelte.ts +++ b/src/lib/core/LocationLite.svelte.ts @@ -44,6 +44,10 @@ export class LocationLite implements Location { ['popstate', 'hashchange'].forEach((event) => { cleanups.push(on(globalThis.window, event, () => { this.#innerState.url.href = globalThis.window?.location?.href; + if (!globalThis.window?.history?.state) { + // Potential hash navigation. Preserve current state. + this.#goTo(this.#innerState.url.href, true, this.#innerState.state); + } this.#innerState.state = globalThis.window?.history?.state ?? this.#innerState.state; })); });