138 lines
3.3 KiB
TypeScript
138 lines
3.3 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import ChildLayout from '../layout/ChildLayout.vue'
|
|
import ParentLayout from '../layout/ParentLayout.vue'
|
|
import ChildrenListView from '../components/ChildrenListView.vue'
|
|
import ChildView from '../components/child/ChildView.vue'
|
|
import ParentView from '../components/child/ParentView.vue'
|
|
import TaskView from '../components/task/TaskView.vue'
|
|
import RewardView from '../components/reward/RewardView.vue'
|
|
import TaskEditView from '@/components/task/TaskEditView.vue'
|
|
import RewardEditView from '@/components/reward/RewardEditView.vue'
|
|
import ChildEditView from '@/components/child/ChildEditView.vue'
|
|
import TaskAssignView from '@/components/child/TaskAssignView.vue'
|
|
import RewardAssignView from '@/components/child/RewardAssignView.vue'
|
|
import NotificationView from '@/components/notification/NotificationView.vue'
|
|
|
|
const routes = [
|
|
{
|
|
path: '/child',
|
|
component: ChildLayout,
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'ChildrenListView',
|
|
component: ChildrenListView,
|
|
},
|
|
{
|
|
path: ':id',
|
|
name: 'ChildView',
|
|
component: ChildView,
|
|
props: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '/parent',
|
|
component: ParentLayout,
|
|
meta: { requiresAuth: true },
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'ParentChildrenListView',
|
|
component: ChildrenListView,
|
|
},
|
|
{
|
|
path: ':id',
|
|
name: 'ParentView',
|
|
component: ParentView,
|
|
props: true,
|
|
},
|
|
{
|
|
path: 'children/create',
|
|
name: 'CreateChild',
|
|
component: ChildEditView,
|
|
},
|
|
{
|
|
path: ':id/edit',
|
|
name: 'ChildEditView',
|
|
component: ChildEditView,
|
|
props: true,
|
|
},
|
|
{
|
|
path: 'tasks',
|
|
name: 'TaskView',
|
|
component: TaskView,
|
|
props: false,
|
|
},
|
|
{
|
|
path: 'tasks/create',
|
|
name: 'CreateTask',
|
|
component: TaskEditView,
|
|
},
|
|
{
|
|
path: 'tasks/:id/edit',
|
|
name: 'EditTask',
|
|
component: TaskEditView,
|
|
props: true,
|
|
},
|
|
{
|
|
path: 'rewards',
|
|
name: 'RewardView',
|
|
component: RewardView,
|
|
props: false,
|
|
},
|
|
{
|
|
path: 'rewards/create',
|
|
name: 'CreateReward',
|
|
component: RewardEditView,
|
|
},
|
|
{
|
|
path: 'rewards/:id/edit',
|
|
name: 'EditReward',
|
|
component: RewardEditView,
|
|
props: true,
|
|
},
|
|
{
|
|
path: ':id/assign-tasks/:type?',
|
|
name: 'TaskAssignView',
|
|
component: TaskAssignView,
|
|
props: true,
|
|
},
|
|
{
|
|
path: ':id/assign-rewards',
|
|
name: 'RewardAssignView',
|
|
component: RewardAssignView,
|
|
props: true,
|
|
},
|
|
{
|
|
path: 'notifications',
|
|
name: 'NotificationView',
|
|
component: NotificationView,
|
|
props: false,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '/',
|
|
redirect: '/child',
|
|
},
|
|
]
|
|
import { isParentAuthenticated } from '../stores/auth'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
})
|
|
|
|
// Auth guard
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.meta.requiresAuth && !isParentAuthenticated.value) {
|
|
// Redirect to /child if trying to access /parent without auth
|
|
next('/child')
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
export default router
|