From 67050f972ee27ccdd3e8f95f514ba9ef3972533b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97zp?= Date: Sun, 30 Mar 2025 00:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=AE=88=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/router/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main/manager-web/src/router/index.js b/main/manager-web/src/router/index.js index 6bc58823..9f68dfb3 100644 --- a/main/manager-web/src/router/index.js +++ b/main/manager-web/src/router/index.js @@ -69,4 +69,22 @@ const router = new VueRouter({ routes }) +// 需要登录才能访问的路由 +const protectedRoutes = ['home', 'RoleConfig', 'DeviceManagement', 'UserManagement', 'ModelConfig'] + +// 路由守卫 +router.beforeEach((to, from, next) => { + // 检查是否是需要保护的路由 + if (protectedRoutes.includes(to.name)) { + // 从localStorage获取token + const token = localStorage.getItem('token') + if (!token) { + // 未登录,跳转到登录页 + next({ name: 'login', query: { redirect: to.fullPath } }) + return + } + } + next() +}) + export default router