修复了@路径报错的问题

This commit is contained in:
carry
2025-02-14 23:59:01 +08:00
parent 119fb96767
commit 817f39e11e
4 changed files with 1058 additions and 30 deletions

35
src/router/index.ts Normal file
View File

@@ -0,0 +1,35 @@
import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/store/userStore'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/login',
name: 'login',
component: () => import('@/views/LoginPage.vue')
},
{
path: '/manage',
name: 'manage',
component: () => import('@/views/ManagePage.vue'),
meta: { requiresAuth: true }
},
{
path: '/',
redirect: '/manage'
}
]
})
router.beforeEach((to, from, next) => {
const userStore = useUserStore()
if (to.meta.requiresAuth && !userStore.isAuthenticated) {
next({ name: 'login' })
} else {
next()
}
})
export default router