import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
const routers = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      name: 'TheCurrentSession',
      meta: {
        requiresAuth: true
        },
      component: resolve => require(['@/pages/TheCurrentSession'], resolve),
    },
    {
      path: '/FastReply',
      name: 'FastReply',
      meta: {
        requiresAuth: true
        },
      component: resolve => require(['@/pages/FastReply'], resolve)
    },
    {
      path: '/LeaveMessage',
      name: 'LeaveMessage',
      meta: {
        requiresAuth: true
        },
      component: resolve => require(['@/pages/LeaveMessage'], resolve)
    },
    {
      path: '/PersonalInformation',
      name: 'PersonalInformation',
      meta: {
        requiresAuth: true
        },
      component: resolve => require(['@/pages/PersonalInformation'], resolve)
    },
    {
      path: '/SessionHistory',
      name: 'SessionHistory',
      requiresAuth: true,
      component: resolve => require(['@/pages/SessionHistory'], resolve)
    },
    {
      path:'/login',
      name:'login',
      component:resolve =>require(['@/pages/login'],resolve)
    }
  ]
})

//路由守卫
routers.beforeEach((to, from, next) => { 
  let token = '';
  if(JSON.parse(localStorage.getItem('user'))){
    token = JSON.parse(localStorage.getItem('user')).token;
  }else{
    token = '';
  }
  if(to.path !='/login'){
    if(!token){
      routers.push({
        path:'/login',
        query: { pid:escape("这就是一个编码没有什么用啊") }
      })
    }
  }
  next();
  // console.log(token);
  //   if(!token){
  //     routers.push({path:'/login'})
  //   }
  //   //next();


  
})





export default routers