add route page to recent when menu load
This commit is contained in:
@@ -5,6 +5,7 @@ import { convertRouteToMenu } from '@/utils/route'
|
||||
import { routes } from '@/router'
|
||||
import type { MenuItemModel } from '@/types/menu'
|
||||
import { splitRoutePath } from '@/utils/texts'
|
||||
import { useCommandPalattesStore } from '@/stores/command'
|
||||
|
||||
export const useMenuStore = defineStore('menu', () => {
|
||||
const route = useRoute()
|
||||
@@ -12,6 +13,7 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
const sidebarOpen = ref(false)
|
||||
const sidebarShowed = ref(true)
|
||||
const router = useRouter()
|
||||
const command = useCommandPalattesStore()
|
||||
const menuSelected = ref(route.fullPath)
|
||||
const toggleSidebar = () => (sidebarOpen.value = !sidebarOpen.value)
|
||||
const toggleSidebarMenu = (path: string, newExpanded: boolean): void => {
|
||||
@@ -54,14 +56,29 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
}
|
||||
})
|
||||
|
||||
watch(router, () => {
|
||||
if (router.currentRoute.value.fullPath === '/' || router.currentRoute.value.fullPath === '/home') {
|
||||
watch(router, (value) => {
|
||||
if (value.currentRoute.value.fullPath === '/' || value.currentRoute.value.fullPath === '/home') {
|
||||
for (const item of navigation.value) {
|
||||
item.expanded = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
watch(menuSelected, (value) => {
|
||||
if (value !== '/login' && value !== '/404' && value !== '/home' && value !== '/') {
|
||||
console.log('current route', value);
|
||||
|
||||
const result = command.searchRoutesPath(routes, value)
|
||||
if (result.length > 0) {
|
||||
const route = result.find((item) => item.path === value)
|
||||
if (route) {
|
||||
command.addRecent(route)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
navigation,
|
||||
toggleSidebar,
|
||||
|
Reference in New Issue
Block a user