lijunke
deploy: clean start with hf metadata
18081cf
import { createRouter, createWebHashHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
const router = createRouter({
history: createWebHashHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/public/uptime',
name: 'public-uptime',
component: () => import('@/views/PublicUptime.vue'),
meta: { requiresAuth: false },
},
{
path: '/public/logs',
name: 'public-logs',
component: () => import('@/views/PublicLogs.vue'),
meta: { requiresAuth: false },
},
{
path: '/login',
name: 'login',
component: () => import('@/views/Login.vue'),
meta: { requiresAuth: false },
},
{
path: '/',
component: () => import('@/layouts/AppShell.vue'),
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'dashboard',
component: () => import('@/views/Dashboard.vue'),
},
{
path: 'accounts',
name: 'accounts',
component: () => import('@/views/Accounts.vue'),
},
{
path: 'settings',
name: 'settings',
component: () => import('@/views/Settings.vue'),
},
{
path: 'logs',
name: 'logs',
component: () => import('@/views/Logs.vue'),
},
{
path: 'monitor',
name: 'monitor',
component: () => import('@/views/Monitor.vue'),
},
{
path: 'docs',
name: 'docs',
component: () => import('@/views/Docs.vue'),
},
{
path: 'gallery',
name: 'gallery',
component: () => import('@/views/Gallery.vue'),
},
],
},
],
})
// 路由守卫
router.beforeEach(async (to) => {
const authStore = useAuthStore()
// 需要认证的路由
if (to.meta.requiresAuth) {
const isAuthenticated = await authStore.checkAuth()
if (!isAuthenticated) {
return { name: 'login' }
}
}
// 已登录用户访问登录页,重定向到首页
if (to.name === 'login' && authStore.isLoggedIn) {
return { name: 'dashboard' }
}
})
export default router