2021-06-27 14:22:20 +02:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router';
|
2021-05-07 17:07:46 +02:00
|
|
|
|
2021-06-27 14:31:46 +02:00
|
|
|
import CoachesList from '../pages/coaches/CoachesList';
|
2021-07-29 17:26:59 +02:00
|
|
|
import store from '../store/index.js';
|
2021-06-27 14:31:46 +02:00
|
|
|
|
2021-07-29 18:49:19 +02:00
|
|
|
const UserAuth = () => import('../pages/auth/UserAuth');
|
|
|
|
const CoachDetails = () => import('../pages/coaches/CoachDetails');
|
|
|
|
const CoachRegistration = () => import('../pages/coaches/CoachRegistration');
|
|
|
|
const ContactCoach = () => import('../pages/requests/ContactCoach');
|
|
|
|
const RequestsRecieved = () => import('../pages/requests/RequestsRecieved');
|
|
|
|
const NotFound = () => import('../pages/NotFound');
|
|
|
|
|
2021-05-07 17:07:46 +02:00
|
|
|
const router = createRouter({
|
2021-06-27 14:22:20 +02:00
|
|
|
history: createWebHistory(),
|
|
|
|
routes: [
|
|
|
|
{ path: '/', redirect: '/coaches' },
|
2021-06-27 16:54:35 +02:00
|
|
|
{ path: '/coaches', component: CoachesList },
|
2021-06-27 14:22:20 +02:00
|
|
|
{
|
|
|
|
path: '/coaches/:id',
|
2021-06-27 17:31:08 +02:00
|
|
|
component: CoachDetails,
|
2021-06-28 18:23:54 +02:00
|
|
|
props: true,
|
2021-06-27 14:31:46 +02:00
|
|
|
children: [{ path: 'contact', component: ContactCoach }]
|
2021-06-27 14:22:20 +02:00
|
|
|
},
|
2021-07-29 17:26:59 +02:00
|
|
|
{
|
|
|
|
path: '/register',
|
|
|
|
component: CoachRegistration,
|
|
|
|
meta: { requiresAuth: true }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/requests',
|
|
|
|
component: RequestsRecieved,
|
|
|
|
meta: { requiresAuth: true }
|
|
|
|
},
|
|
|
|
{ path: '/auth', component: UserAuth, meta: { requiresUnAuth: true } },
|
2021-07-28 21:18:27 +02:00
|
|
|
{ path: '/:notFound(.*)', component: NotFound }
|
2021-06-27 14:22:20 +02:00
|
|
|
]
|
2021-05-07 17:07:46 +02:00
|
|
|
});
|
|
|
|
|
2021-07-29 17:26:59 +02:00
|
|
|
router.beforeEach(function(to, _, next) {
|
|
|
|
if (to.meta.requiresAuth && !store.getters.isAuthenticated) {
|
|
|
|
next('/auth');
|
|
|
|
} else if (to.meta.requiresUnAuth && store.getters.isAuthenticated) {
|
|
|
|
next('/coaches');
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-27 14:22:20 +02:00
|
|
|
export default router;
|