import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routers/index.js?v=Math.random()'

// const root = process.env.API_ROOT
// import store from './store'

Vue.use(VueRouter)

const router = new VueRouter({
    // mode: 'history',
    routes
})

// router.beforeEach((to, from, next) => {
//   if (localStorage.getItem('token') || to.name == 'Login' || to.name == 'Nav' || to.name == 'LoginPage' || process.env.NODE_ENV === 'development') {
//     next()
//   } else {
//     let projectHostName = ''
//     let localhostName = location.href.split('#')[0] // 获取锚点之前的链接
//     if (localhostName.indexOf('localhost') > -1) { //  开发环境
//       projectHostName = 'http://localhost:8080'
//     } else if (localhostName.indexOf('https://gatewaytest.vschool100.com') > -1) { // 测试环境
//       projectHostName = 'https://test.vschool100.com'
//     } else {
//       projectHostName = 'https://oa.vschool100.com'
//     }
//     top.window.location.href = `${projectHostName}/ajax/loginOut.ashx`
//   }
//   next()
// })

router.beforeEach((to, from, next) => {
    if (!to.matched || to.matched.length === 0) {
        router.replace('/error')
    } else {
        next()
    }
})

export default router
