From 12b1d08ea44ac86eb66c1329f5df23e379655567 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Fri, 16 May 2025 13:34:24 +0200 Subject: [PATCH] enhance: navigation optimization --- src/router/adminGuard.ts | 9 ++++++++- src/router/index.ts | 5 +++-- src/stores/admin/navigation.ts | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/router/adminGuard.ts b/src/router/adminGuard.ts index 83d1331..8016b7d 100644 --- a/src/router/adminGuard.ts +++ b/src/router/adminGuard.ts @@ -12,7 +12,14 @@ export async function abilityAndNavUpdate(to: any, from: any, next: any) { let section = to.meta.section; let module = to.meta.module; - if ((admin && ability.isAdmin()) || ability.can(type, section, module)) { + if (to.name == "admin-default") { + navigation.activeNavigation = "club"; + navigation.activeLink = null; + navigation.updateTopLevel(); + navigation.updateNavigation(); + NProgress.done(); + next(); + } else if ((admin && ability.isAdmin()) || ability.can(type, section, module)) { NProgress.done(); navigation.activeNavigation = to.name.split("-")[1]; navigation.activeLink = to.name.split("-")[2]; diff --git a/src/router/index.ts b/src/router/index.ts index 0be84bf..02cbdc3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -15,7 +15,7 @@ const router = createRouter({ routes: [ { path: "/", - redirect: { name: "admin" }, + redirect: { name: "admin-default" }, }, { path: "/login", @@ -76,12 +76,13 @@ const router = createRouter({ path: "/admin", name: "admin", component: () => import("@/views/admin/View.vue"), - beforeEnter: [isAuthenticated], + beforeEnter: [isAuthenticated, abilityAndNavUpdate], children: [ { path: "", name: "admin-default", component: () => import("@/views/admin/ViewSelect.vue"), + beforeEnter: [abilityAndNavUpdate], }, { path: "club", diff --git a/src/stores/admin/navigation.ts b/src/stores/admin/navigation.ts index 7f0d0c9..dfd93f4 100644 --- a/src/stores/admin/navigation.ts +++ b/src/stores/admin/navigation.ts @@ -147,7 +147,8 @@ export const useNavigationStore = defineStore("navigation", { this.activeNavigationObject.main.findIndex((e) => e.key == this.activeLink) == -1 || this.activeLink == "default" ) { - let link = this.activeNavigationObject.main[0].key; + let link = this.activeNavigationObject.main.filter((m) => !m.key.startsWith("divider"))[0].key; + this.activeLink = link; router.push({ name: `admin-${this.activeNavigation}-${link}` }); } },