routerBefore.js
699 Bytes
/**
* 执行路由前的准备工作
*/
/**处理前置钩子逻辑 */
const routerBefore = (next) => {
// console.log("处理前置钩子逻辑");
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;