src/util/url.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// A position can travel in the URL as ?fen=... so a game or puzzle is shareable
// without any account or server.
export function fenFromUrl(): string | null {
const params = new URLSearchParams(location.search);
const fen = params.get("fen");
return fen ? decodeURIComponent(fen) : null;
}
export function routeFromUrl(): string {
const hash = location.hash.replace(/^#\/?/, "");
return hash || "home";
}
export function goto(route: string) {
location.hash = `/${route}`;
}
|