From 998861f36e081b44855a1a84bf78f6d8e3f45294 Mon Sep 17 00:00:00 2001 From: ray_wuhao <443547225@qq.com> Date: Fri, 27 Jan 2023 19:38:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E9=99=86=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E7=82=B9=E5=87=BB=E6=B5=8F=E8=A7=88=E5=99=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 12 ++++++++++-- src/store/modules/menu.ts | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) 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 {