Blame view

src/router/index.js 929 Bytes
406803045 committed
1 2
import Vue from 'vue'
import Router from 'vue-router'
3
import { constantRouterMap } from './router.config.js'
xiaodi committed
4 5 6

// hack router push callback
const originalPush = Router.prototype.push
7
Router.prototype.push = function push(location, onResolve, onReject) {
xiaodi committed
8 9 10
  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)

14 15
const createRouter = () =>
  new Router({
sunnie committed
16 17
    // mode: 'history', // 如果你是 history模式 需要配置vue.config.js publicPath
    // base: process.env.BASE_URL,
18 19 20
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
  })
xiaodi committed
21 22 23 24

const router = createRouter()

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

xiaodi committed
30
export default router