From e0c9b5d67cc7d0616dde03805487c34cc5544480 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Sat, 31 Aug 2024 22:53:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=99=BB=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tonecn/src/router/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tonecn/src/router/index.ts b/tonecn/src/router/index.ts index 3630f42..91eea19 100644 --- a/tonecn/src/router/index.ts +++ b/tonecn/src/router/index.ts @@ -39,9 +39,25 @@ const router = createRouter({ name: 'login', component: () => import('../views/Console/Login.vue') }, + { + path: 'dashboard', + name: 'dashboard', + component: () => import('../views/Console/Dashboard.vue') + } ], } ] }) +router.beforeEach((to, from, next) => { + const isAuthenticated = !!localStorage.getItem('jwtToken'); + if (to.name === 'dashboard' && !isAuthenticated) { + next({ name: 'login' }); + } else if (to.name === 'login' && isAuthenticated) { + next({ name: 'dashboard' }); + } + next() +}) + + export default router