From 0acfbaaa37bc80abfb4e3c1468756200f9a7e935 Mon Sep 17 00:00:00 2001
From: hejianhao <15708179461@qq.com>
Date: 星期三, 08 一月 2025 14:19:23 +0800
Subject: [PATCH] request签名,路由拦截,登录页接口

---
 src/router/index.js |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/src/router/index.js b/src/router/index.js
index 8a15208..0d061eb 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -41,9 +41,24 @@
 ];
 
 const router = new VueRouter({
-  mode: "history",
+  mode: "hash",
   base: process.env.BASE_URL,
   routes,
 });
 
+// 前置路由拦截器
+router.beforeEach((to, from, next) => {
+  console.log(to.path);
+
+  // 没有登录并且要去的页面不是登录页面,强制跳转到登录
+  if (!localStorage.getItem('extra') && to.path !== '/login') {
+    next('/login');
+  } else {
+    if (to.path === '/login') {
+      localStorage.clear();
+    }
+    next();
+  }
+});
+
 export default router;

--
Gitblit v1.7.1