2026-08-11 23:17:04 +07:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
|
|
|
|
|
|
declare module 'vue-router' {
|
|
|
|
|
interface RouteMeta {
|
|
|
|
|
public?: boolean
|
|
|
|
|
screenKey?: string
|
2026-08-24 08:07:23 +07:00
|
|
|
title?: string
|
2026-08-11 23:17:04 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(),
|
|
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
|
|
|
|
component: () => import('../views/auth/LoginView.vue'),
|
|
|
|
|
meta: { public: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
component: () => import('../layouts/MainLayout.vue'),
|
|
|
|
|
children: [
|
|
|
|
|
{ path: '', redirect: '/projects' },
|
2026-08-24 08:07:23 +07:00
|
|
|
{ path: 'dashboard', name: 'dashboard', component: () => import('../views/dashboard/DashboardView.vue'), meta: { screenKey: 'dashboard', title: 'Dashboard' } },
|
|
|
|
|
{ path: 'projects', name: 'projects', component: () => import('../views/projects/ProjectsListView.vue'), meta: { screenKey: 'projects', title: 'Projects' } },
|
|
|
|
|
{ path: 'users', name: 'users', component: () => import('../views/users/UsersView.vue'), meta: { screenKey: 'users', title: 'Users' } },
|
2026-08-11 23:17:04 +07:00
|
|
|
{
|
|
|
|
|
path: 'projects/:id',
|
|
|
|
|
component: () => import('../layouts/ProjectLayout.vue'),
|
|
|
|
|
meta: { screenKey: 'projects' },
|
|
|
|
|
children: [
|
|
|
|
|
{ path: '', name: 'project-overview', component: () => import('../views/projects/ProjectOverviewView.vue') },
|
|
|
|
|
{ path: 'documents', name: 'documents', component: () => import('../views/documents/DocumentsView.vue'), meta: { screenKey: 'documents' } },
|
|
|
|
|
{ path: 'tasks', name: 'tasks', component: () => import('../views/tasks/TasksListView.vue'), meta: { screenKey: 'tasks' } },
|
|
|
|
|
{ path: 'tasks/board', name: 'tasks-board', component: () => import('../views/tasks/TasksBoardView.vue'), meta: { screenKey: 'tasks' } },
|
|
|
|
|
{ path: 'members', name: 'members', component: () => import('../views/projects/MembersView.vue') },
|
|
|
|
|
],
|
|
|
|
|
},
|
2026-08-24 08:07:23 +07:00
|
|
|
{ path: 'settings', name: 'settings', component: () => import('../views/settings/SettingsView.vue'), meta: { title: 'Settings' } },
|
|
|
|
|
{ path: 'profile', name: 'profile', component: () => import('../views/profile/ProfileView.vue'), meta: { title: 'Profile' } },
|
2026-08-11 23:17:04 +07:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{ path: '/:pathMatch(.*)*', redirect: '/projects' },
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach(async (to) => {
|
|
|
|
|
const auth = useAuthStore()
|
|
|
|
|
if (!to.meta.public && !auth.isAuthenticated) {
|
|
|
|
|
return { name: 'login', query: { redirect: to.fullPath } }
|
|
|
|
|
}
|
|
|
|
|
if (to.name === 'login' && auth.isAuthenticated) {
|
2026-08-24 08:07:23 +07:00
|
|
|
return { path: '/dashboard' }
|
2026-08-11 23:17:04 +07:00
|
|
|
}
|
|
|
|
|
if (auth.isAuthenticated) {
|
|
|
|
|
await auth.ensureMenu()
|
|
|
|
|
}
|
|
|
|
|
if (to.meta.screenKey && !auth.canView(to.meta.screenKey)) {
|
2026-08-24 08:07:23 +07:00
|
|
|
if (to.path !== '/dashboard') {
|
|
|
|
|
return { path: '/dashboard' }
|
|
|
|
|
}
|
2026-08-11 23:17:04 +07:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|