all repos — emchess @ e3439f4fd1351a66738e364bb3c2a16038ca6e6a

src/util/url.js (view raw)

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