karl/view/src/stores/route.ts
2021-03-10 01:20:22 +01:00

22 lines
418 B
TypeScript

import { writable } from "svelte/store";
const getHash = () => {
if (window.location.hash.length) {
return window.location.hash.replace("#", "");
} else {
return "main";
}
}
const store = writable<string>(getHash());
store.subscribe(s => {
if (s === "main") s = ""
window.location.hash = s;
})
window.addEventListener("hashchange", () => {
store.set(getHash())
}, false);
export default store;