import Router from 'vue-router'
import routes from '../config/routes'
// import store from '../store'

// 注册路由
Vue.use(Router)

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}
let originalReplace = Router.prototype.replace
Router.prototype.replace = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
    return originalReplace.call(this, location).catch((err) => err)
}

// 配置路由
// const router = new Router({
//     routes: [{
//         path: '*', name: '404', component: (resolve) => require(['@/views/404/index'], resolve),
//     }, ...routes,],
// })

// function acquirePathData(datas, url) {
//     for (let i = 0; i < datas.length; i++) {
//         let item = datas[i]
//         if (item.url == url) {
//             return item
//         }
//         if (item.children && item.children.length > 0) {
//             let res = acquirePathData(item.children, url)
//             if (res) return res
//         }
//     }
// }

// 全局路由守卫
// router.beforeEach((to, from, next) => {
//     // const nextRoute = store.state.menudata.pathList
//     // let nextItem = acquirePathData(nextRoute, to.path)
//     // if (nextItem) {
//     //     next()
//     // } else {
//     //     next(from.path)
//     // }
// })

// export default router
export default new Router({
    routes: [{
        path: '/404', name: '404', component: (resolve) => require(['@/views/404/index'], resolve),
    }, ...routes]
})