修复登陆后,点击浏览器返回按钮跳转错误页问题

This commit is contained in:
ray_wuhao 2023-01-27 19:38:06 +08:00
parent 94dfc524c7
commit 998861f36e
2 changed files with 15 additions and 3 deletions

View File

@ -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()
}

View File

@ -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 {