filter.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Router from 'vue-router'
  2. import router from "./index"
  3. // 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
  4. const originalPush = Router.prototype.push
  5. Router.prototype.push = function push(location) {
  6. return originalPush.call(this, location).catch(err => err)
  7. }
  8. router.beforeEach((to, from, next) => {
  9. console.log(from);
  10. console.log(to);
  11. if (to.fullPath === '/' || to.name === '*') {
  12. let {
  13. code,
  14. ticket
  15. } = to.query;
  16. if (code && ticket) {
  17. next({
  18. path: "/mainPage",
  19. query: {
  20. code,
  21. ticket
  22. },
  23. replace: true
  24. });
  25. } else {
  26. next({
  27. path: "/mainPage",
  28. replace: true
  29. });
  30. }
  31. } else {
  32. if (from.path === '/login' || from.name === 'login') {
  33. if (localStorage.getItem('Authorization')) {
  34. next();
  35. } else {
  36. next(false);
  37. // return false
  38. }
  39. } else {
  40. next();
  41. }
  42. }
  43. });