medusa-wx-router

1.0.5 • Public • Published

medusa-wx-router

基于微信小程序路由功能 API 进行的二次封装函数,提供以同一 API 使用原生四种跳转能力的功能以及参数保真功能。

API 说明

routerTo

通用跳转函数,提供跳转与参数保真功能

参数

属性 类型 默认值 必填 说明
url String - 目标页面路径
type String push 跳转方式
query Object - 跳转参数
success Function - 跳转成功回调函数

示例

import ms from 'medusa-wx-router';
/** 完整调用方式 */
ms.routerTo({
  url: 'pages/home/index',
  type: 'push',
  query: {
    id: 0,
    bool: true
  },
  success: () => console.log('successfully'),
});
/** navigateTo API快捷形式 */
ms.routerTo('pages/home/index', {
  id: 0,
  bool: true
});

type 映射关系

type API
push navigateTo
replace redirectTo
reLaunch reLaunch
switchTab switchTab

decoding

提供参数解析功能

参数

属性 类型 默认值 必填 说明
options Object - onLoad生命周期函数的参数

示例

Page({
  onLoad(options) {
    /** query对象中的属性维持了跳转前的变量类型 */
    const query = ms.decoding(options); // { id: 0, bool: true }
  }
});

back

提供回退功能

参数

属性 类型 默认值 必填 说明
delta Number 1 回退步值

示例

ms.back(delta);

goHome

返回首页功能

示例

ms.goHome();

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i medusa-wx-router

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

8.78 kB

Total Files

5

Last publish

Collaborators

  • gorgon-medusa