import Vue from 'vue'
import VueRouter from 'vue-router'
import { routes } from './routes'
import { afterEach, beforeEach } from '@lywzx/vue.access.control';

Vue.use(VueRouter)
let router = new VueRouter(
{
    mode: 'history',
    routes,
    scrollBehavior(to, from, savedPosition) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({ x: 0, y: 0 })
        }, 500)
      })
    }
}
)

// 解决NavigationDuplicated 报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
//Louise開發暫時駐解 20201015，Osbert說推的時候要把router設定註解移掉
router.beforeEach(beforeEach.bind(router));
router.afterEach(afterEach.bind(router));

export default router
