xiangpei
2025-04-18 7feee0463330ee014b0ac1a6f8e31118bb699f12
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
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'
 
 
Vue.use(VueRouter)
 
const routes = [
  {
    path: '/',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/LoginView.vue')
  },
]
 
 
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: routes
})
 
router.beforeEach((to, from, next) => {
  if (store.state.isFresh === '') {
    store.commit("dynamicRouters", JSON.parse(sessionStorage.getItem("permissions")))
    if (to.name === "Login") {
      next();
    }
    else if (router.options.routes.length === 1) {
      next({ ...to, replace: true })
    }
  }
next()
})
 
// function createRouter(item) {
//     let newRouter = {
//       path: item.menuPath,
//       name: item.routerName,
//       meta: {
//         title: item.menuName
//       },
//       component: () => import(`@/views/${item.routerComponent}.vue`)
//     }
//     //newRouter['component'] = () => import(`@/views/${item.routerComponent}.vue`)
//     return newRouter;
// }
 
export default router