mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-09-02 13:19:52 +08:00
修复登陆后,点击浏览器返回按钮跳转错误页问题
This commit is contained in:
parent
94dfc524c7
commit
998861f36e
@ -1,6 +1,6 @@
|
|||||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||||
import { constantRoutes } from './routes'
|
import { constantRoutes } from './routes'
|
||||||
import { getCache } from '@/utils/cache'
|
import { getCache, setCache } from '@/utils/cache'
|
||||||
|
|
||||||
import type { App } from 'vue'
|
import type { App } from 'vue'
|
||||||
|
|
||||||
@ -42,10 +42,18 @@ export const permissionRouter = () => {
|
|||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
const token = getCache('token')
|
const token = getCache('token')
|
||||||
const route = getCache('menuKey')
|
const route = getCache('menuKey')
|
||||||
|
console.log('route', route)
|
||||||
|
console.log('token', token)
|
||||||
|
|
||||||
if (token !== 'no') {
|
if (token !== 'no') {
|
||||||
if (to.path === '/' || from.path === '/login') {
|
if (to.path === '/' || from.path === '/login') {
|
||||||
next(route)
|
if (route !== 'no') {
|
||||||
|
next(route)
|
||||||
|
} else {
|
||||||
|
next('/dashboard')
|
||||||
|
|
||||||
|
setCache('menuKey', '/dashboard')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { getCache, setCache } from '@/utils/cache'
|
|
||||||
import { NEllipsis } from 'naive-ui'
|
import { NEllipsis } from 'naive-ui'
|
||||||
import RayIcon from '@/components/RayIcon/index'
|
import RayIcon from '@/components/RayIcon/index'
|
||||||
|
|
||||||
|
import { getCache, setCache } from '@/utils/cache'
|
||||||
|
|
||||||
import type { MenuOption } from 'naive-ui'
|
import type { MenuOption } from 'naive-ui'
|
||||||
import type { RouteRecordRaw, RouteMeta } from 'vue-router'
|
import type { RouteRecordRaw, RouteMeta } from 'vue-router'
|
||||||
|
|
||||||
@ -146,6 +147,9 @@ export const useMenu = defineStore('menu', () => {
|
|||||||
(newData) => {
|
(newData) => {
|
||||||
updateMenuKeyWhenRouteUpdate(newData)
|
updateMenuKeyWhenRouteUpdate(newData)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
immediate: true,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user