Add SPA to the Drive project for further usage

This commit is contained in:
2025-07-25 22:47:23 +08:00
parent d13fb8b0e4
commit 123dce564c
41 changed files with 2311 additions and 8 deletions

View File

@@ -0,0 +1,30 @@
import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/stores/user'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'index',
component: () => import('../views/index.vue')
}
]
})
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore()
// Initialize user state if not already initialized
if (!userStore.user && localStorage.getItem('authToken')) {
await userStore.initialize()
}
if (to.matched.some((record) => record.meta.requiresAuth) && !userStore.isAuthenticated) {
next({ name: 'login', query: { redirect: to.fullPath } })
} else {
next()
}
})
export default router