index.js 735 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. // 获取原型对象上的push函数
  5. const originalPush = Router.prototype.push
  6. // 修改原型对象中的push方法
  7. Router.prototype.push = function push(location) {
  8. return originalPush.call(this, location).catch(err => err)
  9. }
  10. const baseRouters = [
  11. {
  12. path: '/',
  13. redirect: '/login'
  14. },
  15. {
  16. path: '/init',
  17. name: 'Init',
  18. component: () => import('@/view/init/index')
  19. },
  20. {
  21. path: '/login',
  22. name: 'Login',
  23. component: () => import('@/view/login/index')
  24. }
  25. ]
  26. // 需要通过后台数据来生成的组件
  27. const createRouter = () => new Router({
  28. routes: baseRouters
  29. })
  30. const router = createRouter()
  31. export default router