80 lines
1.4 KiB
TypeScript
80 lines
1.4 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import store from '../store';
|
|
|
|
export enum PAGE {
|
|
HOME= 'Home',
|
|
AUTH = 'Auth',
|
|
HELP = 'Help',
|
|
REQUEST = 'Request'
|
|
}
|
|
|
|
export const PAGE_URL: Record<PAGE, string> = {
|
|
[PAGE.HOME]: '/',
|
|
[PAGE.REQUEST]: '/request/:id',
|
|
[PAGE.AUTH]: '/auth',
|
|
[PAGE.HELP]: '/help'
|
|
}
|
|
|
|
const routes = [
|
|
{
|
|
path: PAGE_URL[PAGE.HOME],
|
|
name: PAGE.HOME,
|
|
component: () => import('../views/HomePage.vue'),
|
|
meta: {
|
|
layout: 'main',
|
|
auth: true,
|
|
},
|
|
},
|
|
{
|
|
path: PAGE_URL[PAGE.HELP],
|
|
name: PAGE.HELP,
|
|
component: () => import('../views/HelpPage.vue'),
|
|
meta: {
|
|
layout: 'main',
|
|
auth: true,
|
|
},
|
|
},
|
|
{
|
|
path: PAGE_URL[PAGE.AUTH],
|
|
name: PAGE.AUTH,
|
|
component: () => import('../views/AuthPage.vue'),
|
|
meta: {
|
|
layout: 'auth',
|
|
}
|
|
},
|
|
{
|
|
path: PAGE_URL[PAGE.REQUEST],
|
|
name: PAGE.REQUEST,
|
|
component: () => import('../views/RequestPage.vue'),
|
|
meta: {
|
|
layout: 'main',
|
|
layoutProps: {
|
|
back: true
|
|
}
|
|
}
|
|
},
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
linkActiveClass: 'active',
|
|
linkExactActiveClass: 'active',
|
|
});
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const requiredAuth = to.meta.auth;
|
|
if (!requiredAuth) {
|
|
return next();
|
|
}
|
|
|
|
if (store.getters['auth/iseAuth']) {
|
|
next();
|
|
} else {
|
|
next('/auth?message=auth-required');
|
|
}
|
|
})
|
|
|
|
|
|
export default router;
|