redirectTo和navigateTo不能跳转到带有tab选项卡的页面,需要使用switchTab

2023-04-11 11:38:28
"list":[
      {
        "pagePath": "pages/index/index",
        "text":"Home",
        "iconPath":"images/tabBar/home.png",
        "selectedIconPath":"images/tabBar/homeSelected.png"
      },
      {
        "pagePath": "pages/search/search",
        "text": "Search",
        "iconPath": "images/tabBar/search.png",
        "selectedIconPath": "images/tabBar/searchSelected.png"
      },
      {
        "pagePath": "pages/recommend/recommend",
        "text": "Recommend",
        "iconPath": "images/tabBar/recommend.png",
        "selectedIconPath": "images/tabBar/recommendSelected.png"
      },
      {
        "pagePath": "pages/logs/logs",
        "text": "User",
        "iconPath": "images/tabBar/user.png",
        "selectedIconPath": "images/tabBar/userSelected.png"
      }
    ]

在app.json中设立了四个tabBar,但是发现如果想要在这四个界面之间通过bind:tap函数进行跳转不能使用redirectTo和navigateTo。

onGotoOtherPage:function(event){
    wx.navigateTo({
      url: '/pages/notabBar/notabBar',
      success: function(res) {console.log("success")},
      fail: function(res) {console.log(res)},
      complete: function(res) {console.log("complete")},
    })
  },
  onGotoLogsPage:function(event){
    wx.switchTab({
      url: '/pages/logs/logs',
    })
  },

在项目中logs包含tabBar就需要使用switchTab,而且这个函数只能实现具有tabBar的页面。而notabBar没有tabBar使用redirectTo和navigateTo即可。

  • 作者:lemonTree-cool
  • 原文链接:https://blog.csdn.net/shuxiluxian316/article/details/89764119
    更新时间:2023-04-11 11:38:28