Blame view

src/router/index.js 850 Bytes
406803045 committed
1 2
import Vue from 'vue'
import Router from 'vue-router'
xiaodi committed
3 4 5 6 7 8 9 10
import { constantRouterMap } from '@/config/router.config'

// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
406803045 committed
11 12 13

Vue.use(Router)

xiaodi committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27
const createRouter = () => new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
406803045 committed
28

xiaodi committed
29
export default router