# wx.onBeforePageLoad(function listener)

> 基础库 3.5.5 开始支持，低版本需做[兼容处理](1003706)。

> __小程序插件__：支持，需要小程序基础库版本不低于 [3.5.5](1003706)
> 
> __微信 鸿蒙 OS 版__：支持

## 功能描述

监听路由事件引起新的页面实例化时，页面实例化前的事件监听，详见 [页面路由监听](/miniprogram/dev/framework/app-service/route-event-listener.md)。

## 参数

### function listener

路由事件的监听函数

#### 参数

##### Object res


```json
[
  {
    "属性": "path",
    "类型": "string",
    "说明": "页面路径"
  },
  {
    "属性": "query",
    "类型": "Object",
    "说明": "路由参数"
  },
  {
    "属性": "componentFramework",
    "类型": "string",
    "说明": "组件框架",
    "子项": [
      {
        "合法值": "exparser",
        "说明": "旧版小程序组件框架"
      },
      {
        "合法值": "glass-easel",
        "说明": "新版小程序组件框架"
      }
    ]
  },
  {
    "属性": "openType",
    "类型": "string",
    "说明": "路由打开类型"
  },
  {
    "属性": "routeEventId",
    "类型": "string",
    "说明": "路由事件 id"
  }
]
```

> 新旧版本小程序组件框架的说明详见：[glass-easel：新版微信小程序组件框架](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/glass-easel/introduction)

## 示例代码

```js
const func = function (res) {
  console.log(res)
}
wx.onBeforePageLoad(func)
// 取消监听
wx.offBeforePageLoad(func)
```
