hrms-user/src/router/index.ts

57 lines
1.3 KiB
TypeScript

import { createRouter, createWebHistory } from "vue-router"
const MainLayout = () => import("@/views/MainLayout.vue")
const Dashboard = () => import("@/modules/01_dashboard/views/Dashboard.vue")
import ModuleTransfer from "@/modules/02_transfer/router"
import ModuleRetire from "@/modules/03_retire/router"
import ModuleCheckin from "@/modules/04_checkin/router"
import ModuleLeave from "@/modules/05_leave/router"
import ModuleAppealComplain from "@/modules/06_appealComplain/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],
},
},
...ModuleTransfer,
...ModuleRetire,
...ModuleCheckin,
...ModuleLeave,
...ModuleAppealComplain
],
},
],
})
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 {
next()
}
} else {
next()
}
// next();
})
export default router