From 255d7c7eee6df906b6042123fd4ccd1d9a4beb6a Mon Sep 17 00:00:00 2001 From: Nicolas Fryder Date: Thu, 2 Jul 2026 22:15:16 +0200 Subject: [PATCH] Fix admin SPA route resolution Support admin views from both hash-based URLs and path-based URLs. Add compatibility aliases such as activities -> activity to avoid falling back to the dashboard overview. --- apps/admin/site/app.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/admin/site/app.js b/apps/admin/site/app.js index 1699548..3f213d4 100644 --- a/apps/admin/site/app.js +++ b/apps/admin/site/app.js @@ -92,10 +92,37 @@ document.getElementById("logout-btn").addEventListener("click", async () => { // Router — 5 onglets : Vue d'ensemble, Groupes, Activité, Actions, LLM // ------------------------------------------------------------------ const VIEWS = ["dashboard", "bands", "activity", "actions", "llm"]; +const VIEW_ALIASES = { + "": "dashboard", + dashboard: "dashboard", + overview: "dashboard", + bands: "bands", + band: "bands", + activity: "activity", + activities: "activity", + activite: "activity", + activites: "activity", + actions: "actions", + action: "actions", + llm: "llm", +}; + +function normalizeView(raw) { + const key = String(raw || "").trim().toLowerCase().replace(/^\/+|\/+$/g, ""); + const normalized = VIEW_ALIASES[key]; + return VIEWS.includes(normalized) ? normalized : "dashboard"; +} + +function currentViewFromLocation() { + const hashView = normalizeView((location.hash || "").replace(/^#\/?/, "")); + if (location.hash) return hashView; + + const pathParts = location.pathname.split("/").filter(Boolean); + return normalizeView(pathParts[0] || ""); +} function router() { - const hash = (location.hash || "#/dashboard").replace("#/", ""); - const view = VIEWS.includes(hash) ? hash : "dashboard"; + const view = currentViewFromLocation(); state.view = view; document.querySelectorAll(".nav a").forEach((a) => { a.classList.toggle("active", a.dataset.view === view);