Skip to content

Commit c941abe

Browse files
committed
fix: separate custom url logic in function
1 parent c5057ba commit c941abe

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

adminforth/spa/src/components/MenuLink.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
'pl-6 pr-3.5': (isChild && !isSidebarIconOnly && !isSidebarHovering) || (isChild && isSidebarIconOnly && isSidebarHovering),
99
'px-3.5 ': !isChild || (isSidebarIconOnly && !isSidebarHovering),
1010
'max-w-12': isSidebarIconOnly && !isSidebarHovering,
11-
'bg-lightSidebarItemActive dark:bg-darkSidebarItemActive': item.url ? ($route.fullPath === item.url) : (item.resourceId ?
12-
($route.params.resourceId === item.resourceId && $route.name === 'resource-list') :
13-
($route.name === item.path))
11+
'bg-lightSidebarItemActive dark:bg-darkSidebarItemActive': isItemActive(item)
1412
}"
1513
>
1614
<component v-if="item.icon" :is="getIcon(item.icon)"
@@ -62,6 +60,21 @@ import { Tooltip } from '@/afcl';
6260
import { ref, watch, computed } from 'vue';
6361
import { useCoreStore } from '@/stores/core';
6462
import { IconFileImageOutline } from '@iconify-prerendered/vue-flowbite';
63+
import { useRoute } from 'vue-router';
64+
65+
const route = useRoute();
66+
67+
const isItemActive = (item: any) => {
68+
if (item.url) {
69+
return route.fullPath === item.url;
70+
}
71+
72+
if (item.resourceId) {
73+
return route.params.resourceId === item.resourceId && route.name === 'resource-list';
74+
}
75+
76+
return route.name === item.path;
77+
};
6578
6679
const props = defineProps(['item', 'isChild', 'isSidebarIconOnly', 'isSidebarHovering']);
6780

0 commit comments

Comments
 (0)