/** * Vue Router * * @library * * https://router.vuejs.org/en/ */ // Lib imports import Vue from 'vue' // import VueAnalytics from 'vue-analytics' import Router from 'vue-router' import Meta from 'vue-meta' // Routes import paths from './paths' import commonPaths from '@Common/router' paths.map(function(path) { return path['prefix'] = '@JS'; }); commonPaths.map(function(path) { return path['prefix'] = '@Common'; }); let allPaths = paths.concat(commonPaths); function route (options) { let path = options.path; let view = options.view; let name = options.name; let prefix = options.prefix; let meta = (options.meta) ? options.meta : ''; if (prefix == '@JS') { return { name: name || view, path, meta, component: (resovle) => import( `@JS/Home/views/${view}.vue` ).then(resovle) } } else if(prefix == '@Common') { console.log(prefix) console.log(options) return { name: name || view, path, meta, component: (resovle) => import( `@Common/views/${view}.vue` ).then(resovle) } } } Vue.use(Router) // Create a new router const router = new Router({ mode: 'history', routes: allPaths.map(path => route(path)).concat([ { path: '*', redirect: '/Home' } ]), scrollBehavior (to, from, savedPosition) { if (savedPosition) { return savedPosition } if (to.hash) { return { selector: to.hash } } return { x: 0, y: 0 } } }) Vue.use(Meta) router.beforeEach((to, from, next) => { // const isPublic = to.matched.some(record => record.meta.public); // const onlyWhenLoggedOut = to.matched.some(record => record.meta.onlyWhenLoggedOut); // const roles = (to.meta && to.meta.roles) ? to.meta.roles : null; // if (!isPublic && !loggedIn) { // return next({ // path:'/login', // query: {redirect: to.fullPath} // Store the full path to redirect the user to after login // }); // } // // Do not allow user to visit login page or register page if they are logged in // if (loggedIn && onlyWhenLoggedOut && policy) { // return next('/') // } next(); }); export default router