import { createWebHistory, createRouter } from "vue-router"; import store from "./AppStore"; // 공통 import Main from "./main/Main.vue"; import TotalSearch from "./main/TotalSearch.vue"; // 회원관리 import Login from "./login/Login.vue"; import MyInfo from "./user/MyInfo.vue"; import MemberManagement from "./member/MemberManagement.vue"; // 기록물 - 사진 import PicHistorySearch from "./bbsDcry/photo/PicHistorySearch.vue"; import PicHistoryInsert from "./bbsDcry/photo/PicHistoryInsert.vue"; import PicHistoryDetail from "./bbsDcry/photo/PicHistoryDetail.vue"; // 기록물 - 영상 import VideoHistoryInsert from "./bbsDcry/video/VideoHistoryInsert.vue"; import VideoHistoryDetail from "./bbsDcry/video/VideoHistoryDetail.vue"; import VideoHistorySearch from "./bbsDcry/video/VideoHistorySearch.vue"; // 미디어 영상 import MediaVideoInsert from "./bbsMediaVido/MediaVideoInsert.vue"; import MediaVideoDetail from "./bbsMediaVido/MediaVideoDetail.vue"; import MediaVideoSearch from "./bbsMediaVido/MediaVideoSearch.vue"; // 보도자료 import NewsReleaseDetail from "./bbsNesDta/NewsReleaseDetail.vue"; import NewsReleaseInsert from "./bbsNesDta/NewsReleaseInsert.vue"; import NewsReleaseSearch from "./bbsNesDta/NewsReleaseSearch.vue"; // 카테고리 관리 import CategoryManagement from "./ctgry/CategoryManagement.vue"; const routes = [ // 공통 { path: "/", name: "MainPage", component: Main, meta: { authorization: ['ROLE_ADMIN', 'ROLE_USER'] } }, { path: "/TotalSearch.page", name: "TotalSearch", component: TotalSearch }, // 회원관리 { path: "/Login.page", name: "Login", component: Login }, { path: "/MyInfo.page", name: "MyInfo", component: MyInfo, meta: { authorization: ['ROLE_ADMIN', 'ROLE_USER'] } }, { path: "/MemberManagement.page", name: "MemberManagement", component: MemberManagement }, // 기록물 - 사진 { path: "/PicHistorySearch.page", name: "PicHistorySearch", component: PicHistorySearch }, { path: "/PicHistoryInsert.page", name: "PicHistoryInsert", component: PicHistoryInsert }, { path: "/PicHistoryDetail.page", name: "PicHistoryDetail", component: PicHistoryDetail }, // 기록물 - 영상 { path: "/VideoHistorySearch.page", name: "VideoHistorySearch", component: VideoHistorySearch }, { path: "/VideoHistoryInsert.page", name: "VideoHistoryInsert", component: VideoHistoryInsert }, { path: "/VideoHistoryDetail.page", name: "VideoHistoryDetail", component: VideoHistoryDetail }, // 미디어 영상 { path: "/MediaVideoSearch.page", name: "MediaVideoSearch", component: MediaVideoSearch }, { path: "/MediaVideoInsert.page", name: "MediaVideoInsert", component: MediaVideoInsert }, { path: "/MediaVideoDetail.page", name: "MediaVideoDetail", component: MediaVideoDetail }, // 보도자료 { path: "/NewsReleaseSearch.page", name: "NewsReleaseSearch", component: NewsReleaseSearch }, { path: "/NewsReleaseInsert.page", name: "NewsReleaseInsert", component: NewsReleaseInsert }, { path: "/NewsReleaseDetail.page", name: "NewsReleaseDetail", component: NewsReleaseDetail }, // 카테고리 관리 { path: "/CategoryManagement.page", name: "CategoryManagement", component: CategoryManagement }, ]; const AppRouter = createRouter({ history: createWebHistory(), routes, // 모든 라우트 이동 후 페이지 상단으로 스크롤 scrollBehavior() { return { top: 0 } }, }); AppRouter.beforeEach((to, from, next) => { const routeExists = AppRouter.getRoutes().some(route => route.path === to.path || (route.name && route.name === to.name)); const userId = store.state.userId; const { authorization } = to.meta; // 로그인 상태 확인 const isLoggedIn = userId; // 로그인되지 않은 경우 if (isLoggedIn == null && to.path !== '/Login.page') { alert('로그인이 필요합니다.'); return next('/Login.page'); // 로그인 페이지로 리다이렉트 } // 권한이 없을 경우 if (authorization) { if (!authorization.includes(store.state.roles[0].authority)) { alert('접근 권한이 없습니다.'); return next(from.path); } } if (!routeExists) { next('/'); return; } next(); }); export default AppRouter;