码迷,mamicode.com
首页 > Web开发 > 详细

后台中src-router-index.js文件详情

时间:2020-11-20 11:59:20      阅读:15      评论:0      收藏:0      [点我收藏+]

标签:表示   children   get   order   turn   pre   rect   def   each   

后台中src-router-index.js文件详情

import Vue from ‘vue‘
import VueRouter from ‘vue-router‘
// import Login from ‘../components/Login.vue‘
const Login = () => import(/* webpackChunkName:"login_Index_Welcome" */ ‘../components/Login.vue‘)
const Index = () => import(/* webpackChunkName:"login_Index_Welcome" */ ‘../components/index.vue‘)
const Welcome = () => import(/* webpackChunkName:"login_Index_Welcome" */ ‘../components/welcome.vue‘)
// import Index from ‘../components/index.vue‘
// import Welcome from ‘../components/welcome.vue‘
// import Users from ‘../components/user/users.vue‘
const Users = () => import(/* webpackChunkName:"user" */ ‘../components/user/users.vue‘)
// import roles from ‘../components/power/roles.vue‘
// import rights from ‘../components/power/rights.vue‘
const roles = () => import(/* webpackChunkName:"power" */ ‘../components/power/roles.vue‘)
const rights = () => import(/* webpackChunkName:"power" */ ‘../components/power/rights.vue‘)
// import Goods from ‘../components/goods/goods.vue‘
// import Categories from ‘../components/goods/categories.vue‘
// import Params from ‘../components/goods/params.vue‘
// import lloo from ‘../components/goods/lloo.vue‘
const Goods = () => import(/* webpackChunkName:"goods" */ ‘../components/goods/goods.vue‘)
const Categories = () => import(/* webpackChunkName:"goods" */ ‘../components/goods/categories.vue‘)
const Params = () => import(/* webpackChunkName:"goods" */ ‘../components/goods/params.vue‘)
const lloo = () => import(/* webpackChunkName:"goods" */ ‘../components/goods/lloo.vue‘)
// import Orders from ‘../components/orders/orders.vue‘
const Orders = () => import(/* webpackChunkName:"orders" */ ‘../components/orders/orders.vue‘)
// import Reports from ‘../components/repots/reports.vue‘
const Reports = () => import(/* webpackChunkName:"repots" */ ‘../components/repots/reports.vue‘)
// import Meimei from ‘../components/meimei/meimei.vue‘
const Meimei = () => import(/* webpackChunkName:"meimei" */ ‘../components/meimei/meimei.vue‘)
Vue.use(VueRouter)
const routes = [{
  path: ‘/‘,
  redirect: ‘/Login‘
},
{
  path: ‘/login‘,
  component: Login
},
{
  path: ‘/index‘,
  component: Index,
  redirect: ‘/welcome‘,
  children: [
    { path: ‘/welcome‘, component: Welcome },
    { path: ‘/users‘, component: Users },
    { path: ‘/roles‘, component: roles },
    { path: ‘/rights‘, component: rights },
    { path: ‘/goods‘, component: Goods },
    { path: ‘/categories‘, component: Categories },
    { path: ‘/params‘, component: Params },
    { path: ‘/goods/lloo‘, component: lloo },
    { path: ‘/orders‘, component: Orders },
    { path: ‘/reports‘, component: Reports },
    { path: ‘/meimei‘, component: Meimei }
  ]
}
]

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

export default router

 

后台中src-router-index.js文件详情

标签:表示   children   get   order   turn   pre   rect   def   each   

原文地址:https://www.cnblogs.com/wsm777/p/13982973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!