-
Notifications
You must be signed in to change notification settings - Fork 5
/
router.js
50 lines (45 loc) · 937 Bytes
/
router.js
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
import Vue from 'vue'
import Router, {
RouterMount
} from 'uni-simple-router';
Vue.use(Router)
const whitelist = { //声明了一个白名单
'/pages/tabbar/tabbar-1/tabbar-1': 'tabbar-1',
'/pages/tabbar/tabbar-2/tabbar-2': 'tabbar-2',
'/pages/tabbar/tabbar-3/tabbar-3': 'tabbar-3',
'/pages/tabbar/tabbar-4/tabbar-4': 'tabbar-4',
'/pages/tabbar/tabbar-5/tabbar-5': 'tabbar-5',
}
//初始化
const router = new Router({
routes: ROUTES.concat([{
path: '*',
name: 'moddle',
redirect: to => {
console.log(to)
const name = whitelist[to.path];
if (name) {
return {
name
}
};
// return {
// name: '404'
// }
}
}])
});
let count = 0;
//全局路由前置守卫
router.beforeEach((to, from, next) => {
console.log(to, from,'XXXXXXXXX')
next()
})
// 全局路由后置守卫
router.afterEach((to, from) => {
console.log(to, from,'afterEach----守卫')
})
export {
RouterMount,
router
}