1.要在微信小程序中跳转到 tabBar 页面,你需要使用 wx.switchTab API。下面是基本的语法:
wx.switchTab({
url: '/pages/tabbar-page/tabbar-page' // tabBar页面路径,注意不需要加 .json
})
其中,url 是跳转的目标页面路径,需要是一个 tabBar 页面的路径,注意不需要加 .json 后缀。你也可以传递一些参数给目标页面,如:
wx.switchTab({
url: '/pages/tabbar-page/tabbar-page?id=123'
})
2.在目标页面中可以通过 options 对象获取这些参数:
Page({
onLoad(options) {
console.log(options.id) // 输出:123
}
})
需要注意的是,wx.switchTab 只能用于跳转到 tabBar 页面,如果你要跳转到非 tabBar 页面,可以使用 wx.navigateTo 或者 wx.redirectTo。