import { createWebHistory, createRouter } from "vue-router"; import Main from '../pages/main/Main.vue'; import Login from "./common/Login.vue"; import Modeling from "./subPage/Modeling.vue"; import Asset from "./subPage/Asset.vue"; import FeedBack from "./subPage/FeedBack.vue"; import Find from "./common/Find.vue"; import Join from "./common/Join.vue"; import AppStore from "./AppStore"; const routes = [ { path: '/', children: [ { path: '', name: 'Main', component: Main }, { path: 'login.page', name: 'Login', component: Login }, { path: 'find.page', name: 'Find', component: Find, props: route => ({ type: route.query.type }) }, { path: 'join.page', name: 'Join', component: Join }, { path: 'modeling.page', name: 'Modeling', component: Modeling }, { path: 'asset.page', name: 'Asset', component: Asset }, { path: 'feedback.page', name: 'FeedBack', component: FeedBack }, // { path: 'error.page', name: 'Error', component: Error, props: () => ({ type: 'ip' }) }, ] }, ]; const AppRouter = createRouter({ history: createWebHistory(), routes, }); AppRouter.beforeEach((to, from, next) => { const isLoggedIn = !!AppStore.state.authorization; const publicPages = ['/login.page', '/find.page', '/join.page']; const isPublic = publicPages.includes(to.path); if (!isLoggedIn && !isPublic) { // 로그인 안 되어 있는데 비공개 페이지 접근 → 로그인 페이지로 next({ path: '/login.page' }); } else if (isLoggedIn && to.path === '/login.page') { // 로그인 상태에서 로그인 페이지 접근 시 메인으로 리다이렉트 next({ path: '/' }); } else { next(); // 정상 접근 } }); export default AppRouter;