From 1ed5ca11e0926f7361927fed4050ef7478c8ce7b Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 24 Jun 2023 19:45:45 +0800 Subject: [PATCH] fix router --- src/router/index.ts | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 0dea34c5..75ee2e0a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -10,46 +10,64 @@ const router = createRouter({ children: [ { path: 'dashboard', - component: () => import('../pages/dashboard.vue') + component: () => import('../pages/dashboard.vue'), }, { path: 'ranking', component: () => import('../pages/ranking.vue'), + meta: { + requiresAuth: true, + }, }, { path: 'resources', component: () => import('../pages/resources.vue'), + meta: { + requiresAuth: true, + }, }, { path: 'subscribe-movie', component: () => import('../pages/subscribe-movie.vue'), + meta: { + requiresAuth: true, + }, }, { path: 'subscribe-tv', component: () => import('../pages/subscribe-tv.vue'), + meta: { + requiresAuth: true, + }, }, { path: 'downloading', component: () => import('../pages/downloading.vue'), + meta: { + requiresAuth: true, + }, }, { path: 'history', component: () => import('../pages/history.vue'), + meta: { + requiresAuth: true, + }, }, - { + { path: 'sites', component: () => import('../pages/sites.vue'), meta: { - requiresAuth: true - } + requiresAuth: true, + }, }, { path: 'account-settings', component: () => import('../pages/account-settings.vue'), meta: { - requiresAuth: true - } - } + requiresAuth: true, + }, + }, ], }, { @@ -79,7 +97,8 @@ router.beforeEach((to, from, next) => { if (to.meta.requiresAuth && !isAuthenticated) { // 如果路由需要登录权限且用户未登录,则跳转到登录页面 next('/login') - } else { + } + else { // 否则,允许继续进行路由导航 next() } @@ -89,6 +108,7 @@ router.beforeEach((to, from, next) => { function checkLoginStatus() { // 在此处检查用户的登录状态,例如从本地存储中读取令牌或其他登录相关的信息 const token = localStorage.getItem('token') + return !!token // 返回一个布尔值,表示用户是否已登录 }