import Vue from 'vue'
import Router from 'vue-router'
import index from '../views/index.vue'
import PageOne from '../views/PageOne.vue'
import PageTwo from '../views/PageTwo.vue'
import PageThree from '../views/PageThree.vue'
import PageFor from '../views/PageFor.vue'
import login from '../views/login/index.vue'
Vue.use(Router)
const router = new Router({
mode: 'history',
routes: [
{
path: '/login',
name: '登录',
meta: {
show:false,
requireAuth:false
},
component: login
},
{
path: '/',
name: '物品管理',
component: index,
meta: {
show:true,
requireAuth:true
},
redirect: '/PageOne',
children: [
{
path: '/PageOne',
name: '物品添加',
component: PageOne
},
{
path: '/PageTwo',
name: '物品删除',
component: PageTwo
}
]
},
{
path: '/two',
name: '导航二',
component: index,
meta: {
show:true,
requireAuth:true
},
children: [
{
path: '/PageThree',
name: 'PageThree',
component: PageThree
},
{
path: '/PageFor',
name: 'PageFor',
component: PageFor,
meta: {
show:true,
requireAuth:true
},
}
]
}
]
})
router.beforeEach((to,from,next)=>{
if(to.meta.requireAuth){
let token = JSON.parse(window.localStorage.getItem('token'))
if(token!=null){
if(token=='qwerqwerwer'){
next()
}else{
next({path:'/err'})
}
}else{
next({path:'/login'})
}
}else{
next()
}
})
export default router