import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routers/index.js'

Vue.use(VueRouter)

const router = new VueRouter({
    // mode: 'history',
    scrollBehavior (to, from, savedPosition) {
        return {
            x: 0,
            y: 0
        }
    },
    routes
})

// router.beforeEach((to, from, next) => {
//     let requireToken = (to.meta.requireToken !== undefined) && (!to.meta.requireToken)
//     if (localStorage.getItem('access_token') || to.name === 'LoginSucc' || to.name === 'VIndex' || requireToken) {
//         next()
//     } else {
//         next()
//     // 退出登录页面
//     }
// })

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

export default router
