routerBefore.js
839 Bytes
class RouterBefore {
constructor(options) {
console.log('---------------- 路由初始化 ----------------')
this.initPageProxy()
}
/**监听页面 */
pageLeaveProxy(thisPage) {
let onLoad = thisPage.onLoad
thisPage.onLoad = function () {
const event = getApp().globalData.ROUTE_QUERY
let options = {
...event,
...arguments[0]
}
getApp().globalData.ROUTE_QUERY = {}
onLoad && onLoad.apply(this, [options]),(this.options = options)
}
}
/**全局注册事件 */
initPageProxy() {
let thisPage = Page
let _this = this
Page = function (el) {
try {
el || (el = {}), _this.pageLeaveProxy(el), thisPage.apply(this, arguments)
} catch (el) {
thisPage.apply(this, arguments)
}
}
}
}
export default new RouterBefore()