index.js 1.15 KB
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // 首页
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/home/home')
  },
  // 第二页
  {
    path: '/homeTwo',
    name: 'HomeTwo',
    component: () => import('../views/homeTwo/homeTwo')
  },
  // 第三页
  {
    path: '/pay',
    name: 'Pay',
    component: () => import('../views/pay/pay')
  },
  // 结果页
  {
    path: '/result',
    name: 'Result',
    component: () => import('../views/result/result')
  },
  {
    path: '*',
    // 首页
    redirect: { path: "/home" }
    // redirect: { path: "/home",query:{id:1} }

  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
// //重写VueRouter.prototype身上的push方法
const originPush = VueRouter.prototype.push;
// // const originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function push(location) {
  return originPush.call(this, location).catch(err => err)
}

//全局守卫:前置守卫(在路由跳转之间进行判断)
router.beforeEach(async (to, from, next) => {
  next()
});

export default router