This commit is contained in:
艾贤凌
2026-03-16 12:05:55 +08:00
parent af3a7c83e8
commit 6d4a72161f
33 changed files with 5671 additions and 178 deletions

View File

@@ -1,23 +1,69 @@
import {createRouter, createWebHistory} from 'vue-router'
import Index from "../views/index.vue";
import { createRouter, createWebHistory } from 'vue-router'
// 需要登录才能访问的路由名称
const AUTH_ROUTES = ['Index', 'Withdraw']
// 不需要登录即可访问的路由名称(白名单)
const PUBLIC_ROUTES = ['Login', 'LinuxdoBind', 'Agree']
// 示例路由配置
const routes = [
{
path: '/',
name: 'Home',
component: Index,
redirect: '/login'
},
{
path: '/login', name: 'Login',
path: '/login',
name: 'Login',
component: () => import('@/views/login.vue')
}
},
{
path: '/linuxdo-bind',
name: 'LinuxdoBind',
component: () => import('@/views/linuxdo-bind.vue')
},
{
path: '/index',
name: 'Index',
component: () => import('@/views/index.vue'),
meta: { requiresAuth: true }
},
{
path: '/play',
name: 'Play',
redirect: '/index',
},
{
path: '/agree',
name: 'Agree',
component: () => import('@/views/agree.vue')
},
{
path: '/withdraw',
name: 'Withdraw',
component: () => import('@/views/withdraw.vue'),
meta: { requiresAuth: true }
},
]
const router = createRouter({
history: createWebHistory(),
routes
routes,
})
// ─── 全局路由守卫 ─────────────────────────────────────────────────────────────
router.beforeEach((to, from, next) => {
const token = sessionStorage.getItem('CQ-TOKEN')
const isLoggedIn = !!token
if (to.meta?.requiresAuth && !isLoggedIn) {
// 需要登录但未登录 → 跳转登录页
next({ path: '/login', query: { redirect: to.fullPath } })
} else if (to.name === 'Login' && isLoggedIn) {
// 已登录访问登录页 → 跳转游戏主页
next({ path: '/index' })
} else {
next()
}
})
export default router