小程序使用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

posted @ 2019-09-19 11:29  奔跑的痕迹  阅读(1029)  评论(0编辑  收藏  举报