diff --git a/src/router/index.ts b/src/router/index.ts index a68aaf07..238658a1 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,6 @@ import { createRouter, createWebHashHistory } from 'vue-router' import { constantRoutes } from './routes' -import { getCache } from '@/utils/cache' +import { getCache, setCache } from '@/utils/cache' import type { App } from 'vue' @@ -42,10 +42,18 @@ export const permissionRouter = () => { router.beforeEach((to, from, next) => { const token = getCache('token') const route = getCache('menuKey') + console.log('route', route) + console.log('token', token) if (token !== 'no') { if (to.path === '/' || from.path === '/login') { - next(route) + if (route !== 'no') { + next(route) + } else { + next('/dashboard') + + setCache('menuKey', '/dashboard') + } } else { next() } diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index 51265167..9b74be36 100644 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -1,7 +1,8 @@ -import { getCache, setCache } from '@/utils/cache' import { NEllipsis } from 'naive-ui' import RayIcon from '@/components/RayIcon/index' +import { getCache, setCache } from '@/utils/cache' + import type { MenuOption } from 'naive-ui' import type { RouteRecordRaw, RouteMeta } from 'vue-router' @@ -146,6 +147,9 @@ export const useMenu = defineStore('menu', () => { (newData) => { updateMenuKeyWhenRouteUpdate(newData) }, + { + immediate: true, + }, ) return {