whyczyk
2021-09-07 69f949b70f1cd2c80a9738afe602905b18e72e0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
 
Vue.use(VueRouter);
 
const router = new VueRouter({
  routes
});
 
//解决vue路由重复导航错误
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
 
/* eslint-disable */
router.beforeEach((to, from, next) => {
  if (to.name != 'login' && (!sessionStorage.getItem('uid') || sessionStorage.getItem('uid') == -1)) {
    next('\login');
  } else {
    next();
  }
});
/* eslint-disable */
 
export default router;