hrms-user/src/router/index.ts

58 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-07-21 16:34:06 +07:00
import { createRouter, createWebHistory } from "vue-router"
2023-07-07 16:54:53 +07:00
2023-07-21 16:34:06 +07:00
const MainLayout = () => import("@/views/MainLayout.vue")
const Dashboard = () => import("@/modules/01_dashboard/views/Dashboard.vue")
2023-07-07 16:54:53 +07:00
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"
2023-08-08 14:03:12 +07:00
// TODO: ใช้หรือไม่?
import keycloak from "@/plugins/keycloak"
2023-07-07 16:54:53 +07:00
const router = createRouter({
2023-07-21 16:34:06 +07:00
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: "/",
name: "home",
component: MainLayout,
children: [
{
path: "/",
name: "dashboard",
component: Dashboard,
2023-08-08 14:03:12 +07:00
meta: {
Auth: true,
Key: [7],
},
2023-07-21 16:34:06 +07:00
},
...ModuleTransfer,
...ModuleRetire,
...ModuleCheckin,
...ModuleLeave,
...ModuleAppealComplain
2023-07-21 16:34:06 +07:00
],
},
],
2023-07-07 16:54:53 +07:00
})
2023-08-08 14:03:12 +07:00
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();
})
2023-07-21 16:34:06 +07:00
export default router