瀏覽代碼

更新 permission.js 中路由权限的判定, 当前有一个 bug 是登录成功后路由不会跳转

reghao 2 年之前
父節點
當前提交
e458a9690a
共有 1 個文件被更改,包括 8 次插入28 次删除
  1. 8 28
      src/permission.js

+ 8 - 28
src/permission.js

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