mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:11:07 +03:30
60 lines
1.2 KiB
JavaScript
Vendored
60 lines
1.2 KiB
JavaScript
Vendored
/**
|
|
* Vue Router
|
|
*
|
|
* @library
|
|
*
|
|
* https://router.vuejs.org/en/
|
|
*/
|
|
|
|
// Lib imports
|
|
import Vue from 'vue'
|
|
import Router from 'vue-router'
|
|
import Meta from 'vue-meta'
|
|
import { TokenService } from '@/services'
|
|
// Routes
|
|
import paths from './paths'
|
|
|
|
function route (options) {
|
|
let path = options.path;
|
|
let view = options.view;
|
|
let name = options.name;
|
|
let meta = (options.meta) ? options.meta : '';
|
|
return {
|
|
name: name || view,
|
|
path,
|
|
meta,
|
|
component: (resovle) => import(
|
|
`@show/views/${view}.vue`
|
|
).then(resovle)
|
|
}
|
|
}
|
|
|
|
Vue.use(Router)
|
|
// Create a new router
|
|
const router = new Router({
|
|
mode: 'history',
|
|
routes: paths.map(path => route(path)).concat([
|
|
{ path: '*', redirect: '/' }
|
|
]),
|
|
|
|
})
|
|
|
|
Vue.use(Meta)
|
|
|
|
// import {$hasRole} from '@/services/acl/role';
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const isPublic = to.matched.some(record => record.meta.public);
|
|
const onlyWhenLoggedOut = to.matched.some(record => record.meta.onlyWhenLoggedOut);
|
|
const loggedIn = !!TokenService.getToken();
|
|
|
|
if (loggedIn && onlyWhenLoggedOut ) {
|
|
window.location.href = '/dashboard';
|
|
}
|
|
|
|
next();
|
|
});
|
|
|
|
|
|
export default router
|