import Vue from 'vue'
import VueRouter from 'vue-router'
import { privateRoutes } from './private-routes'
import { publicRoutes } from './public-routes'
import store from '@/store/index'

Vue.use(VueRouter)

// 解决路由跳转 代码执行两次 重复触发了同一个路由 路由劫持报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [...publicRoutes] // 做权限的时候 删除 ...privateRoutes
})

export default router
