编程语言
首页 > 编程语言> > mpvue开发微信小程序navigateBack失效于tabBar

mpvue开发微信小程序navigateBack失效于tabBar

作者:互联网

返回上一层的navigateBack路由要是与配置的tabBar栏目路由相同的话,返回会失效,需换用switchTab

//app.json里面设置的tabBar
"tabBar": {
    "list": [
      {
        "text": "返利",
        "pagePath": "pages/index/main",
        "iconPath": "static/images/menu_home.png",
        "selectedIconPath": "static/images/menu_home_active.png"
      },
      {
        "text": "平台",
        "pagePath": "pages/hello/main",
        "iconPath": "static/images/menu_platform.png",
        "selectedIconPath": "static/images/menu_platform_active.png"
      }

    ]
  },
<!-- template -->
<a @click="navigateBack" class="home">后退</a>

methods: {
    navigateBack(){
      wx.navigateBack({
        delta: 1,
        success: () => {
          console.log('success')
        },
        fail: () => {
          console.log('fail')
        }
      })
    },
}

另外,mpvue里面,用标签属性做路由跳转的话,open-type属性值要注意:
1.open-type="switchTab" 跳转tabBar路由
2.open-type="navigate" 跳转非tabBar路由(默认值)

<a href="/pages/index/main" open-type="switchTab" class="home">去往首页-way1</a>
<a href="/pages/counter/main" open-type="navigate" class="home">去往counter</a>
<navigator open-type="navigateBack" delta="1">返回非tabBar</navigator>
<navigator url="/pages/index/main" open-type="switchTab" delta="1">跳转tabBar</navigator>

 

标签:mpvue,navigateBack,微信,static,tabBar,跳转,images,路由
来源: https://blog.csdn.net/qq_42221334/article/details/89398174