| | |
| | | import Vue from 'vue' |
| | | import Router from 'vue-router' |
| | | |
| | | import Cookies from "js-cookie"; |
| | | Vue.use(Router) |
| | | |
| | | /* Layout */ |
| | |
| | | return routerPush.call(this, location).catch(err => err) |
| | | } |
| | | |
| | | export default new Router({ |
| | | const router = new Router({ |
| | | mode: 'history', // 去掉url中的# |
| | | scrollBehavior: () => ({ y: 0 }), |
| | | routes: constantRoutes |
| | | }) |
| | | |
| | | router.beforeEach((to, from, next) => { |
| | | if (from.path === '/login') { |
| | | // 获取当前环境 |
| | | const env = process.env.VUE_APP_ENV |
| | | // 生产环境处理 |
| | | if (env === 'production') { |
| | | // 防止用户通过地址栏直接输入URL访问 |
| | | if (from.name === null && to.path !== window.location.pathname) { |
| | | next(false) |
| | | return |
| | | } |
| | | } |
| | | } |
| | | next() |
| | | }) |
| | | |
| | | export default router |