import Vue from 'vue' import VueRouter from 'vue-router' import store from '@/store' Vue.use(VueRouter) const router = new VueRouter({ routes: [ { path: '/', name: 'Home', meta: { isAuth: true }, redirect: '/Welcome', component: () => import('../view/Home.vue'), children: [ { path: 'welcome', name: 'welcome', component: () => import('../view/Welcome.vue') }, { path: 'changePwd', name: 'changePwd', component: () => import('../view/login/ChangePwd') }, { path: 'normalSendGoods', name: 'NormalSendGoods', component: () => import('../view/NormalSendGoods.vue') }, { path: 'message', name: 'message', component: () => import('../view/Message.vue') }, { path: 'copyProduct', name: 'copyProduct', component: () => import('../view/CopyProduct.vue') }, { path: 'saleData', name: 'saleData', component: () => import('../view/ExportSaleData.vue') }, // { // path: 'statistics', // name: 'statistics', // component: () => import('../view/Statistics.vue') // }, { path: 'learning', name: 'learning', component: () => import('../view/Learning.vue') } ] }, { path: '/login', name: 'login', meta: { title: '登录' }, component: () => import('../view/login/Login.vue') }, { path: '/register', name: 'register', meta: { title: '注册' }, component: () => import('../view/login/Register.vue') } ], scrollBehavior (to, from, savedPosition) { if (savedPosition) { return savedPosition } else { return { x: 0, y: 0 } } } }) router.beforeEach((to, from, next) => { const isLogin = !!store.state.token if (to.meta.isAuth && !isLogin) { next({ path: '/login', query: { redirect: to.fullPath } }) } else { next() } }) const originalPush = VueRouter.prototype.push VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) } export default router