import Vue from 'vue'; import VueRouter from 'vue-router'; const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch((err) => err); }; Vue.use(VueRouter); const routes = [ { path: '/', redirect: '/login', }, { path: '/exam', name: 'exam', meta: { title: '考试' }, component: () => import(/* webpackChunkName: "exam" */ '../views/exam.vue'), }, { path: '/login', name: 'login', meta: { title: '登陆' }, component: () => import(/* webpackChunkName: "login" */ '../views/login.vue'), }, { path: '/test', name: 'test', meta: { title: '测试' }, component: () => import(/* webpackChunkName: "test" */ '../views/test.vue'), }, ]; const router = new VueRouter({ mode: 'hash', // base: process.env.VUE_APP_ROUTER, routes, }); router.beforeEach((to, from, next) => { document.title = `${to.meta.title} `; const noCheck = _.get(to, 'meta.noCheck', false); if (noCheck) next(); else { const token = localStorage.getItem('token'); // if (!token) next('/login'); // else next(); next(); } }); export default router;