import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  { path: '/', name: 'home' },
  {
    path: '/home',
    name: 'home',
    meta: { title: 'LNG商用车服务' },
    component: () => import('@/views/home/index')
  }, {
    path: '/list',
    name: 'list',
    meta: { title: '搜索车辆' },
    component: () => import('@/views/home/list')
  }, {
    path: '/truck',
    name: 'truck',
    meta: { title: '车辆信息' },
    component: () => import('@/views/home/truck')
  }, {
    path: '/trail',
    name: 'trail',
    meta: { title: '轨迹回放' },
    component: () => import('@/views/home/trail')
  }
]

const router = new VueRouter({
  routes: [...routes]
})

// router.beforeEach((to, from, next) => {
//   const mwxtoken = getLocalStorage('mwxtoken')
//
//   if (to.meta.title) { // 每页增加title
//     document.title = to.meta.title
//   }
//   if (mwxtoken) {
//     if (to.name === 'main') return next('/boss')
//     return next()
//   }
//   if (to.name === 'login' || to.name === 'agreement') return next()
//   return next('/login')
// })

export default router
