Fix Stop + broken buttons: use location.reload() which preserves hash but fully unloads page, killing workers and audio. Revert pathname routing (unnecessary).

This commit is contained in:
David Alvarez
2026-05-23 19:29:07 +02:00
parent f6a1dccdf2
commit 7f17f4b31e
2 changed files with 8 additions and 33 deletions
+4 -30
View File
@@ -8,28 +8,7 @@
let route = $state("/");
let gameId = $state(null);
function parseRoute() {
// Check pathname first (full page navigations from Stop button)
const path = window.location.pathname.replace(/\/+$/, "") || "/";
if (path !== "/") {
const parts = path.split("/").filter(Boolean);
if (parts.length >= 2) {
const [routeName, routeId] = parts;
if (routeName === "game" || routeName === "play") {
route = "/" + routeName;
gameId = routeId;
// Sync the hash so hash-based links still work
window.history.replaceState(null, "", "#/" + routeName + "/" + routeId);
return;
}
}
// Unknown path, reset to home
route = "/";
gameId = null;
return;
}
// Fall back to hash-based routing (SPA transitions)
function parseHash() {
const hash = window.location.hash.slice(1) || "/";
const parts = hash.split("/").filter(Boolean);
if (parts.length === 0 || (parts.length === 1 && parts[0] === "")) {
@@ -49,15 +28,10 @@
// Listen for hash changes and page loads
$effect(() => {
parseRoute();
const handler = () => parseRoute();
parseHash();
const handler = () => parseHash();
window.addEventListener("hashchange", handler);
// Also listen for popstate (for browser back/forward)
window.addEventListener("popstate", handler);
return () => {
window.removeEventListener("hashchange", handler);
window.removeEventListener("popstate", handler);
};
return () => window.removeEventListener("hashchange", handler);
});
</script>