小程序使用wx.navigateTo无法跳转到加了tabBar的页面

随着小程序的不断更新,发现目前的小程序版本使用navigator无法跳转到加了tabBar的页面;后来使用redirectTo进行跳转也不行;在刚开始也是纠结了好久一直找不到解决办法。最后从官方文档中找到了答案,在这记录一下(不熟悉文档有多坑)。

官方对wx.navigateTo的解释

在这里插入图片描述

官方对wx.redirectTo的解释

在这里插入图片描述

解决办法使用wx.switchTab

在这里插入图片描述

官方文档地址 https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.redirectTo.html



页面跳转实例


Page({
  onTap: function() {
    // 这个跳转无效
    // wx.navigateTo({
    //   url: '../posts/post',
    // })
    // 这个跳转也无效
    // wx.redirectTo({
    //   url: '../posts/post',
    // });
  // 使用这个就可以跳转
    wx.switchTab({
      url: '../posts/post',
    })
  }
})

tabBar配置参考官方 https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html



另一种是使用 open-type

官方案例:

<!-- sample.wxml -->
<view class="btn-area">
  <navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>
  <navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
  <navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
  <navigator target="miniProgram" open-type="navigate" app-id="" path="" extra-data="" version="release">打开绑定的小程序</navigator>
</view>



官方文档地址 https://developers.weixin.qq.com/miniprogram/dev/component/navigator.html
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奔跑的痕迹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值