import { createWebHistory, createRouter } from "vue-router"; // 공통페이지 import Main from "./main/Main.vue"; import NotFound from "./etc/NotFound.vue"; const routes = [ { path: "/", name: "MainPage", component: Main }, { path: "/notFound.page", name: "NotFoundPage", component: NotFound }, ]; 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)); if (!routeExists) { next({ name: 'NotFoundPage' }); return; } next(); }); export default AppRouter;