import { useSyncExternalStore } from "react"; /** Hash routes: #/ , #/s/, #/new, #/settings[/tab], #/stats */ export function useRoute(): string[] { const hash = useSyncExternalStore( (l) => { window.addEventListener("hashchange", l); return () => window.removeEventListener("hashchange", l); }, () => location.hash, ); return hash.replace(/^#\/?/, "").split("/").filter(Boolean); } export function navigate(path: string) { location.hash = path.startsWith("/") ? path : `/${path}`; }