Spaces:
Running
Running
Commit
·
77c3cea
1
Parent(s):
f2d331b
feat: switch to hash-based routing for better static hosting
Browse files- Change router from createWebHistory to createWebHashHistory
- Update useRoomHash to use query params instead of hash for room IDs
- URLs now: /#/vs-people?room=ABC12345
trigo-web/app/dist/assets/{index-CxJ9O80R.js → index-BsbKWb8A.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
trigo-web/app/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>Trigo - 3D Go Game</title>
|
| 8 |
-
<script type="module" crossorigin src="/assets/index-
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-Siwlapuk.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>Trigo - 3D Go Game</title>
|
| 8 |
+
<script type="module" crossorigin src="/assets/index-BsbKWb8A.js"></script>
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-Siwlapuk.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
trigo-web/app/src/composables/useRoomHash.ts
CHANGED
|
@@ -1,37 +1,43 @@
|
|
| 1 |
/**
|
| 2 |
-
* Composable for managing room ID in URL
|
| 3 |
* Enables shareable room links for VS People multiplayer mode
|
|
|
|
|
|
|
|
|
|
| 4 |
*/
|
| 5 |
|
| 6 |
export function useRoomHash() {
|
| 7 |
/**
|
| 8 |
-
* Extract room ID from URL
|
| 9 |
-
* @returns Room ID string or null if no
|
| 10 |
*/
|
| 11 |
function getRoomIdFromHash(): string | null {
|
| 12 |
-
const
|
| 13 |
-
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
|
| 17 |
/**
|
| 18 |
-
* Update URL
|
| 19 |
* Uses replaceState to avoid adding browser history entry
|
| 20 |
* @param roomId - 8-character uppercase alphanumeric room ID
|
| 21 |
*/
|
| 22 |
function updateHash(roomId: string): void {
|
| 23 |
-
const
|
| 24 |
-
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
|
| 28 |
/**
|
| 29 |
-
* Remove
|
| 30 |
-
* Clears room
|
| 31 |
*/
|
| 32 |
function clearHash(): void {
|
| 33 |
-
const
|
| 34 |
-
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
|
|
|
|
| 1 |
/**
|
| 2 |
+
* Composable for managing room ID in URL
|
| 3 |
* Enables shareable room links for VS People multiplayer mode
|
| 4 |
+
*
|
| 5 |
+
* With hash-based routing, we use query parameters for room IDs:
|
| 6 |
+
* e.g., /#/vs-people?room=ABC12345
|
| 7 |
*/
|
| 8 |
|
| 9 |
export function useRoomHash() {
|
| 10 |
/**
|
| 11 |
+
* Extract room ID from URL query parameter
|
| 12 |
+
* @returns Room ID string or null if no room param present
|
| 13 |
*/
|
| 14 |
function getRoomIdFromHash(): string | null {
|
| 15 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 16 |
+
const roomId = urlParams.get("room");
|
| 17 |
+
return roomId || null;
|
| 18 |
}
|
| 19 |
|
| 20 |
|
| 21 |
/**
|
| 22 |
+
* Update URL with room ID query parameter
|
| 23 |
* Uses replaceState to avoid adding browser history entry
|
| 24 |
* @param roomId - 8-character uppercase alphanumeric room ID
|
| 25 |
*/
|
| 26 |
function updateHash(roomId: string): void {
|
| 27 |
+
const url = new URL(window.location.href);
|
| 28 |
+
url.searchParams.set("room", roomId);
|
| 29 |
+
window.history.replaceState(null, "", url.toString());
|
| 30 |
}
|
| 31 |
|
| 32 |
|
| 33 |
/**
|
| 34 |
+
* Remove room ID from URL
|
| 35 |
+
* Clears room query parameter from address bar
|
| 36 |
*/
|
| 37 |
function clearHash(): void {
|
| 38 |
+
const url = new URL(window.location.href);
|
| 39 |
+
url.searchParams.delete("room");
|
| 40 |
+
window.history.replaceState(null, "", url.toString());
|
| 41 |
}
|
| 42 |
|
| 43 |
|
trigo-web/app/src/router/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { createRouter,
|
| 2 |
import TrigoView from "@/views/TrigoView.vue";
|
| 3 |
import OnnxTestView from "@/views/OnnxTestView.vue";
|
| 4 |
import TrigoAgentTestView from "@/views/TrigoAgentTestView.vue";
|
|
@@ -7,7 +7,7 @@ import SocketTestView from "@/views/SocketTestView.vue";
|
|
| 7 |
import MCTSAnalysisView from "@/views/MCTSAnalysisView.vue";
|
| 8 |
|
| 9 |
const router = createRouter({
|
| 10 |
-
history:
|
| 11 |
routes: [
|
| 12 |
{
|
| 13 |
path: "/",
|
|
|
|
| 1 |
+
import { createRouter, createWebHashHistory } from "vue-router";
|
| 2 |
import TrigoView from "@/views/TrigoView.vue";
|
| 3 |
import OnnxTestView from "@/views/OnnxTestView.vue";
|
| 4 |
import TrigoAgentTestView from "@/views/TrigoAgentTestView.vue";
|
|
|
|
| 7 |
import MCTSAnalysisView from "@/views/MCTSAnalysisView.vue";
|
| 8 |
|
| 9 |
const router = createRouter({
|
| 10 |
+
history: createWebHashHistory(import.meta.env.BASE_URL),
|
| 11 |
routes: [
|
| 12 |
{
|
| 13 |
path: "/",
|
trigo-web/app/src/views/TrigoView.vue
CHANGED
|
@@ -1319,23 +1319,24 @@
|
|
| 1319 |
|
| 1320 |
|
| 1321 |
/**
|
| 1322 |
-
* Handle browser navigation (back/forward) and
|
|
|
|
| 1323 |
*/
|
| 1324 |
-
function
|
| 1325 |
if (gameMode.value !== "vs-people") return;
|
| 1326 |
|
| 1327 |
-
const
|
| 1328 |
const currentRoom = playerStore.roomId;
|
| 1329 |
|
| 1330 |
-
if (
|
| 1331 |
-
if (
|
| 1332 |
-
// User navigated to different room
|
| 1333 |
if (currentRoom) socketApi.leaveRoom();
|
| 1334 |
-
joinRoomByHash(
|
| 1335 |
} else {
|
| 1336 |
-
// Invalid
|
| 1337 |
if (currentRoom) {
|
| 1338 |
-
updateHash(currentRoom); // Restore correct
|
| 1339 |
} else {
|
| 1340 |
createAndJoinRoom(); // Create new room
|
| 1341 |
}
|
|
@@ -1601,8 +1602,8 @@
|
|
| 1601 |
playerStore.setPlayerId(socketApi.socket.id);
|
| 1602 |
}
|
| 1603 |
|
| 1604 |
-
// Listen for browser navigation (back/forward) and
|
| 1605 |
-
window.addEventListener("
|
| 1606 |
|
| 1607 |
// Handle socket connection and reconnection
|
| 1608 |
socketApi.socket.on("connect", () => {
|
|
@@ -1686,8 +1687,8 @@
|
|
| 1686 |
socketApi.offError();
|
| 1687 |
cleanupRoomListeners();
|
| 1688 |
|
| 1689 |
-
// Remove
|
| 1690 |
-
window.removeEventListener("
|
| 1691 |
}
|
| 1692 |
|
| 1693 |
// Disconnect ResizeObserver
|
|
|
|
| 1319 |
|
| 1320 |
|
| 1321 |
/**
|
| 1322 |
+
* Handle browser navigation (back/forward) and URL changes
|
| 1323 |
+
* With hash routing, room IDs are in query params, so we listen for popstate
|
| 1324 |
*/
|
| 1325 |
+
function handleUrlChange() {
|
| 1326 |
if (gameMode.value !== "vs-people") return;
|
| 1327 |
|
| 1328 |
+
const currentRoomParam = getRoomIdFromHash();
|
| 1329 |
const currentRoom = playerStore.roomId;
|
| 1330 |
|
| 1331 |
+
if (currentRoomParam !== currentRoom) {
|
| 1332 |
+
if (currentRoomParam && isValidRoomId(currentRoomParam)) {
|
| 1333 |
+
// User navigated to different room
|
| 1334 |
if (currentRoom) socketApi.leaveRoom();
|
| 1335 |
+
joinRoomByHash(currentRoomParam);
|
| 1336 |
} else {
|
| 1337 |
+
// Invalid or removed room param
|
| 1338 |
if (currentRoom) {
|
| 1339 |
+
updateHash(currentRoom); // Restore correct room param
|
| 1340 |
} else {
|
| 1341 |
createAndJoinRoom(); // Create new room
|
| 1342 |
}
|
|
|
|
| 1602 |
playerStore.setPlayerId(socketApi.socket.id);
|
| 1603 |
}
|
| 1604 |
|
| 1605 |
+
// Listen for browser navigation (back/forward) and URL changes
|
| 1606 |
+
window.addEventListener("popstate", handleUrlChange);
|
| 1607 |
|
| 1608 |
// Handle socket connection and reconnection
|
| 1609 |
socketApi.socket.on("connect", () => {
|
|
|
|
| 1687 |
socketApi.offError();
|
| 1688 |
cleanupRoomListeners();
|
| 1689 |
|
| 1690 |
+
// Remove URL change listener
|
| 1691 |
+
window.removeEventListener("popstate", handleUrlChange);
|
| 1692 |
}
|
| 1693 |
|
| 1694 |
// Disconnect ResizeObserver
|