Преглед изворни кода

更新 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) => {
   const needAuth = to.meta.needAuth
   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: '/' })
   } else {
     next()
@@ -22,5 +36,5 @@ router.beforeEach((to, from, next) => {
     if (token === null) {
       next('/login')
     }
-  }
+  }*/
 })