From 9f85cc1e3af2fe4774cec287485911964b3bef67 Mon Sep 17 00:00:00 2001 From: zry <18990852002@163.com> Date: Tue, 15 Jul 2025 13:09:40 +0800 Subject: [PATCH] router modified --- src/router/index.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 69191b2..c997889 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -80,18 +80,16 @@ const router = createRouter({ ] }); + router.beforeEach((to, from, next) => { - const token = localStorage.getItem("token"); - const machineId = localStorage.getItem("machineId"); - - // 允许无token访问的路由 - const publicRoutes = ['Login', 'PasswordSuccess']; - - if (!publicRoutes.includes(to.name) && !token) { - next(`/login?machineId=${machineId}`); - return; - } - - next(); -}); + const token = localStorage.getItem("token"); + const machineId = localStorage.getItem("machineId"); + if (to.name != "login" && !token) { + next('/login?machineId=' + machineId); + } + next(); +}) + + + export default router;