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

import { createRouter, createWebHistory } from 'vue-router';
import CoachesList from '../pages/coaches/CoachesList';
import store from '../store/index.js';
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');
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', redirect: '/coaches' },
{ path: '/coaches', component: CoachesList },
{
path: '/coaches/:id',
component: CoachDetails,
props: true,
children: [{ path: 'contact', component: ContactCoach }]
},
{
path: '/register',
component: CoachRegistration,
meta: { requiresAuth: true }
},
{
path: '/requests',
component: RequestsRecieved,
meta: { requiresAuth: true }
},
{ path: '/auth', component: UserAuth, meta: { requiresUnAuth: true } },
{ path: '/:notFound(.*)', component: NotFound }
]
});
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();
}
});
export default router;