import { createRouter, createWebHistory } from "vue-router" const MainLayout = () => import("@/views/MainLayout.vue") const Dashboard = () => import("@/views/Dashboard.vue") const Error404NotFound = () => import("@/views/Error404NotFound.vue") import ModuleManual from "@/modules/01_manual/router" // TODO: ใช้หรือไม่? import keycloak from "@/plugins/keycloak" const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: "/", name: "home", component: MainLayout, children: [ // { // path: "/", // name: "dashboard", // component: Dashboard, // meta: { // Auth: true, // Key: [7], // Role: "dashboard", // }, // }, ...ModuleManual, ], }, /** * 404 Not Found * ref: https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route */ { // path: "/:catchAll(.*)*", // TODO: ใช้ pathMatch แทนตามในเอกสารแนะนำ คงไว้เผื่อจำเป็น path: "/:pathMatch(.*)*", component: Error404NotFound, }, ], scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition } else if (to.hash) { return { el: to.hash, behavior: "smooth", } } }, }) router.beforeEach((to, from, next) => { // if (to.meta.Auth) { // if (!keycloak.authenticated) { // keycloak.login({ // redirectUri: `${window.location.protocol}//${window.location.host}${to.path}`, // locale: "th", // }) // } else { // // keycloak.updateToken(60); // const role = keycloak.tokenParsed?.role // if (role.includes(to.meta.Role)) { // next() // } else { // next({ path: "" }) // // next(); // } // } // } else { // next() // } next() }) export default router