小程序开放平台

文档中心
基础
路由
navigateBack
navigateTo
reLaunch
redirectTo
switchTab
openXhsDeeplink
跳转
转发
界面
网络
支付
数据缓存
媒体
位置
开放接口
设备
XHSML
性能
第三方平台
文件
数据分析
画布

xhs.switchTab

开发
>
JS API
>
路由
>
switchTab
>
更新时间:2024-11-28 20:05:21

以Promise风格调用: 支持

跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面

参数

Object object

属性
类型
默认值
必填
说明
urlstring需要跳转的 tabBar 页面的路径 (代码包路径)(需在 app.json 的 tabBar 字段定义的页面),路径后不能带参数。
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

属性
类型
说明
errMsgstring

实例代码

jsonapp.json
// app.json
{
  "tabBar": {
    "list": [{
      "pagePath": "index",
      "text": "首页"
    },{
      "pagePath": "other",
      "text": "其他"
    }]
  }
}
xhs.switchTab({
  url: '/index'
})