فهرست منبع

更新 permission.js 中的判断逻辑

reghao 2 سال پیش
والد
کامیت
956f68926b
1فایلهای تغییر یافته به همراه16 افزوده شده و 2 حذف شده
  1. 16 2
      src/permission.js

+ 16 - 2
src/permission.js

@@ -4,7 +4,21 @@ import { getAccessToken } from '@/utils/auth'
 router.beforeEach((to, from, next) => {
 router.beforeEach((to, from, next) => {
   const needAuth = to.meta.needAuth
   const needAuth = to.meta.needAuth
   const token = getAccessToken()
   const token = getAccessToken()
-  if (to.path === '/login' && token !== null) {
+  if (needAuth) {
+    if (token == null) {
+      next('/login')
+    } else {
+      if (to.path === '/login') {
+        next({ path: '/' })
+      } else {
+        next()
+      }
+    }
+  } else {
+    next()
+  }
+
+  /*if (to.path === '/login' && token !== null) {
     next({ path: '/' })
     next({ path: '/' })
   } else {
   } else {
     next()
     next()
@@ -22,5 +36,5 @@ router.beforeEach((to, from, next) => {
     if (token === null) {
     if (token === null) {
       next('/login')
       next('/login')
     }
     }
-  }
+  }*/
 })
 })