hejianhao
2025-01-10 e6eb5dccecce12a0b6dacf21c8fa2904c896dbaa
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Vue from "vue";
import VueRouter from "vue-router";
import Layouts from "../layouts";
 
Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
 
/**
 *  path: "/login",   ------页面地址
    component: () => import("../views/login"),  ------组件地址
    meta: {
      title: "登录",    ------页面标题
      icon: "el-icon-user-solid",  ------菜单图标
      oneself: true,  ------是否在单独页面打开
      hide: true,  ------是否隐藏改菜单
    }
 */
 
const routes = [
  {
 
    path: "",
    redirect: "login",
    component: Layouts,
    children: [
      {
        path: "/home",
        meta: {
          title: "首页",
        },
        component: () => import("../view/Home.vue"),
      },
      {
        path: "/login",
        meta: {
          title: "登录",
        },
        component: () => import("../view/Login.vue"),
      },
      {
        path: "/addOrder",
        meta: {
          title: "添加订单",
          oneself: true,
          hide: true,
          privilege: 'addOrder'
        },
        component: () => import("../view/addOrder"),
      },
    ]
  }
];
 
const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});
 
// 路由拦截
router.beforeEach((to, from, next) => {
  const extra = localStorage.getItem('extra');
  if (!extra && to.path !== '/login') {
    next('/login');
  } else if (extra && to.path === '/login') {
    next('/home');
  } else {
    if (to.path === '/login') {
      localStorage.clear();
    }
    next();
  }
});
 
export default router;