style: 路由守卫
This commit is contained in:
parent
402787bfae
commit
3f8fa531af
@ -1,5 +1,4 @@
|
||||
import router from "@/router"
|
||||
import { RouteLocationNormalized } from "vue-router"
|
||||
import { useUserStoreHook } from "@/store/modules/user"
|
||||
import { usePermissionStoreHook } from "@/store/modules/permission"
|
||||
import { ElMessage } from "element-plus"
|
||||
@ -11,14 +10,14 @@ import "nprogress/nprogress.css"
|
||||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
router.beforeEach(async (to: RouteLocationNormalized, _: RouteLocationNormalized, next: any) => {
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
NProgress.start()
|
||||
const userStore = useUserStoreHook()
|
||||
const permissionStore = usePermissionStoreHook()
|
||||
// 判断该用户是否登录
|
||||
if (getToken()) {
|
||||
if (to.path === "/login") {
|
||||
// 如果登录,并准备进入 Login 页面,则重定向到主页
|
||||
// 如果已经登录,并准备进入 Login 页面,则重定向到主页
|
||||
next({ path: "/" })
|
||||
NProgress.done()
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user