index.js
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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