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 = Vue.prototype.$token;
  if(to.fullPath !='/login'){
    if(!token){
      routers.push({path:'/login'})
    }
  }
  next();
  // console.log(token);
  //   if(!token){
  //     routers.push({path:'/login'})
  //   }
  //   //next();


  
})





export default routers