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.
This commit is contained in:
parent
222e71a608
commit
255d7c7eee
1 changed files with 29 additions and 2 deletions
|
|
@ -92,10 +92,37 @@ document.getElementById("logout-btn").addEventListener("click", async () => {
|
||||||
// Router — 5 onglets : Vue d'ensemble, Groupes, Activité, Actions, LLM
|
// Router — 5 onglets : Vue d'ensemble, Groupes, Activité, Actions, LLM
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
const VIEWS = ["dashboard", "bands", "activity", "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() {
|
function router() {
|
||||||
const hash = (location.hash || "#/dashboard").replace("#/", "");
|
const view = currentViewFromLocation();
|
||||||
const view = VIEWS.includes(hash) ? hash : "dashboard";
|
|
||||||
state.view = view;
|
state.view = view;
|
||||||
document.querySelectorAll(".nav a").forEach((a) => {
|
document.querySelectorAll(".nav a").forEach((a) => {
|
||||||
a.classList.toggle("active", a.dataset.view === view);
|
a.classList.toggle("active", a.dataset.view === view);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue