index.js 799 B

12345678910111213141516171819202122232425262728
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import { constantRouterMap } from '@/config/router.config'
  4. // hack router push callback
  5. const originalPush = Router.prototype.push
  6. Router.prototype.push = function push (location, onResolve, onReject) {
  7. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  8. return originalPush.call(this, location).catch(err => err)
  9. }
  10. Vue.use(Router)
  11. const createRouter = () =>
  12. new Router({
  13. mode: 'history',
  14. routes: constantRouterMap
  15. })
  16. const router = createRouter()
  17. // 定义一个resetRouter 方法,在退出登录后或token过期后 需要重新登录时,调用即可
  18. export function resetRouter () {
  19. const newRouter = createRouter()
  20. router.matcher = newRouter.matcher
  21. }
  22. export default router