routerBefore.js 784 Bytes
class RouterBefore {
  constructor(options) {
    console.log('---------------- 路由初始化 ----------------')
    this.initPageProxy()
  }
  /**监听页面 */
  pageLeaveProxy(thisPage) {
    let onLoad = thisPage.onLoad
    thisPage.onLoad = function () {
      let options = {
        ...getApp().globalData.ROUTE_QUERY,
        ...arguments[0]
      }
      onLoad && onLoad.apply(this, [options]),(getApp().globalData.ROUTE_QUERY = {})
    }
  }
  /**全局注册事件 */
  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()