From afb94ad3e1bbd8fb74cf2b07eb9b58ab3046df38 Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Sat, 15 Feb 2025 16:24:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=AE=88=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 12 ++++++++---- tsconfig.app.json | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index b041033..b81499a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,5 +1,5 @@ import { createRouter, createWebHistory } from 'vue-router' -import { useUserStore } from '@/store/userStore' +import { userStore } from '@/store/userStore' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -18,20 +18,24 @@ const router = createRouter({ { path: '/', redirect: '/manage' + }, + { + path: '/:pathMatch(.*)*', + redirect: '/login' } ] }) router.beforeEach((to, from, next) => { - const userStore = useUserStore() + //const userStore = useUserStore() // 如果路由需要认证但用户未登录 - if (to.meta.requiresAuth && !userStore.isLoggedIn) { + if (to.meta.requiresAuth && !userStore().isLoggedIn) { next({ name: 'login' }) } // 如果用户已登录但访问登录页 - else if (to.name === 'login' && userStore.isLoggedIn) { + else if (to.name === 'login' && userStore().isLoggedIn) { next({ name: 'manage' }) } // 其他情况正常导航 diff --git a/tsconfig.app.json b/tsconfig.app.json index 7fb078c..19ef853 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -8,7 +8,10 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true + "noUncheckedSideEffectImports": true, + "paths": { + "@/*": ["./src/*"] + } }, "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"] }