tt.navigateToMiniProgram

2020-02-12 17:24 更新

跳转到另一个小程序


输入

继承标准对象输入,扩展属性描述:

属性类型必填默认值说明最低支持版本
appIdstring要跳转的小程序 id1.15.0
pathstring要跳转的小程序页面路径(不传则默认打开首页),允许携带 query 参数,格式详见示例1.15.0
extraDataobject需要传递给目标小程序的数据,目标小程序可在 App.onLaunchApp.onShowtt.getLaunchOptionsSync 中获取到这份数据。如果跳转的是小游戏,可以在 tt.onShowtt.getLaunchOptionsSync 中可以获取到这份数据数据1.15.0
envVersionstringcurrent要打开的小程序版本。合法的值有current--线上版;latest--测试版。仅在当前小程序为开发版或测试版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版1.15.0
successfunction接口调用成功的回调函数1.15.0
completefunction接口调用结束的回调函数(调用成功、失败都会执行)1.15.0
failfunction接口调用失败的回调函数1.15.0


代码示例

// app.json
{
  ...
  "navigateToMiniProgramAppIdList": [
    "tt2d495bf4b2xxxxxx"
  ],
  ...
}
tt.navigateToMiniProgram({
  appId: "tt2d495bf4b2xxxxxx",
  path: "pages/index/index?arg1=ascii&arg2=" + encodeURIComponent("中文"),
  extraData: {
    arg3: "hello"
  },
  success: function() {
    that.setData({
      success: true
    });
  },
  fail: function(e) {
    console.log(e);
    that.setData({
      success: false
    });
  }
});


Bug & Tip

  1. 该方法需要预先在app.json中配置navigateToMiniProgramAppIdList属性。每个小程序可跳转的其他小程序数量限制为不超过10个
  2. 只能在 bindtap 中使用该 api,并且会弹窗询问是否允许跳转
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号