Skip to content

Commit db8eb4f

Browse files
authored
feat: Support the use of regular HTML anchor elements for hash routing universes (#51)
* feat: Support the use of regular HTML anchor elements for hash routing universes * fix: Do replaceState() to preserve state on possible <a> hash navigation
1 parent 5e63d74 commit db8eb4f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib/core/LocationLite.svelte.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ 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-
this.#innerState.state = globalThis.window?.history?.state;
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+
}
51+
this.#innerState.state = globalThis.window?.history?.state ?? this.#innerState.state;
4852
}));
4953
});
5054
return () => {

0 commit comments

Comments
 (0)