routerBefore.js
928 Bytes
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
// import { IMG_URL } from '~/utils/constantData'
/**
* 执行路由前的准备工作
*/
/**处理前置钩子逻辑 */
const routerBefore = next => {
// console.log("处理前置钩子逻辑");
// 配置图片全局路径
// let page = wx.$router.getPageInstance()
// page && (page.data.IMG_URL = IMG_URL)
// page && page.setData({ IMG_URL })
// console.log()
// console.log(next)
next()
}
/**处理后置钩子逻辑 */
const routerAfter = next => {
// console.log("处理后置钩子逻辑");
next()
}
// 重写Page方法
const OldPage = Page
Page = function (options) {
const oldShow = options.onShow
const oldHide = options.onHide
options.onShow = function () {
routerBefore(() => {
oldShow.apply(this, arguments)
})
}
options.onHide = function () {
routerAfter(() => {
oldHide.apply(this, arguments)
})
}
OldPage(options)
}
export default routerBefore