{"size": 2093, "ext": "js", "max_stars_repo_path": "web/src/router/index.js", "max_stars_repo_name": "ZhOUCFff/E-commerce_Back", "max_stars_repo_stars_event_min_datetime": "2020-09-17T07:15:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-17T07:15:54.000Z", "max_issues_repo_path": "web/src/router/index.js", "max_issues_repo_name": "ZhOUCFff/E-commerce_Back", "max_issues_repo_issues_event_min_datetime": "2021-03-10T07:33:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T23:39:24.000Z", "max_forks_repo_path": "web/src/router/index.js", "max_forks_repo_name": "ZhOUCFff/E-commerce_Back", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 21.5773195876, "max_line_length": 72, "alphanum_fraction": 0.5527950311}
import Vue from 'vue'
import VueRouter from 'vue-router'

//路由懒加载
const Login = () => import('views/login/Login')
const Home = () => import('views/home/Home')
const Welcome = () => import('views/home/childCpns/Welcome')
const UserList = () => import('views/home/childCpns/user/UserList')
const Rights = () => import('views/home/childCpns/power/Rights')
const Roles = () => import('views/home/childCpns/power/Roles')
const Categories = () => import('views/home/childCpns/goods/Categories')
const Params = () => import('views/home/childCpns/goods/Params')
const Goods = () => import('views/home/childCpns/goods/Goods')
const Add = () => import('views/home/childCpns/goods/Add')
const OrderList = () => import('views/home/childCpns/order/OrderList')
const Report = () => import('views/home/childCpns/report/Report')


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    children: [
      {
        path: '/',
        redirect: '/users'
      },
      {
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/users',
        component: UserList
      },
      {
        path: '/rights',
        component: Rights
      },
      {
        path: '/roles',
        component: Roles
      },
      {
        path: '/categories',
        component: Categories
      },
      {
        path: '/params',
        component: Params
      },
      {
        path: '/goods',
        component: Goods,
      },
      {
        path: '/goods/add',
        component: Add
      },
      {
        path: '/orders',
        component: OrderList
      },
      {
        path: '/reports',
        component: Report
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  //to代表将要访问的路径
  //from代表从哪个路径跳转而来
  //next是一个函数，表示放行
  if (to.path === '/login') return next()
  const token = window.sessionStorage.getItem('token')
  if (!token) return next('/login')
  next()
})

export default router