Parcourir la source

添加登录判断

zy1125 il y a 1 an
Parent
commit
f0672c97ed
1 fichiers modifiés avec 10 ajouts et 0 suppressions
  1. 10 0
      src/router/index.js

+ 10 - 0
src/router/index.js

@@ -20,4 +20,14 @@ const router = createRouter({
20 20
   routes
21 21
 })
22 22
 
23
+
24
+router.beforeEach(function(to, from, next) {
25
+  if (!localStorage.getItem("myAdminToken")) {
26
+      if (to.path !== '/login') {
27
+          return next('/login')
28
+      }
29
+  }
30
+  next()
31
+})
32
+
23 33
 export default router