This repository has been archived on 2021-07-29. You can view files and clone it, but cannot push or open issues or pull requests.
find_coach/src/router/index.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

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' },
{ 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,
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;