2026-07-11 07:50:47 +09:00
|
|
|
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
|
|
|
|
import MainLayout from '@/layouts/MainLayout.vue'
|
2026-07-11 08:35:00 +09:00
|
|
|
import { useAuthStore } from '@/stores/auth'
|
2026-07-11 07:50:47 +09:00
|
|
|
|
|
|
|
|
const routes: RouteRecordRaw[] = [
|
2026-07-11 08:35:00 +09:00
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
|
|
|
|
component: () => import('@/pages/LoginPage.vue'),
|
|
|
|
|
},
|
2026-07-11 07:50:47 +09:00
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
component: MainLayout,
|
2026-07-11 08:35:00 +09:00
|
|
|
meta: { requiresAuth: true },
|
2026-07-11 07:50:47 +09:00
|
|
|
children: [
|
|
|
|
|
{ path: '', name: 'home', component: () => import('@/pages/HomePage.vue') },
|
|
|
|
|
{ path: 'profile', name: 'profile', component: () => import('@/pages/ProfilePage.vue') },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(),
|
|
|
|
|
routes,
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-11 08:35:00 +09:00
|
|
|
// 소셜 로그인 전용 앱: 미로그인 시 보호 경로 접근 → 로그인으로
|
|
|
|
|
router.beforeEach((to) => {
|
|
|
|
|
const auth = useAuthStore()
|
|
|
|
|
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
|
|
|
|
return { name: 'login', query: { redirect: to.fullPath } }
|
|
|
|
|
}
|
|
|
|
|
if (to.name === 'login' && auth.isAuthenticated) {
|
|
|
|
|
return { name: 'home' }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-11 07:50:47 +09:00
|
|
|
export default router
|