傳回上一層的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" target="_blank" rel="external nofollow" open-type="switchTab" class="home">去往首頁-way1</a>
<a href="/pages/counter/main" target="_blank" rel="external nofollow" 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>
Tip
1.wx.navigateTo和wx.redirectTo不允許跳轉到tabBar頁面,隻能用wx.switchTab跳轉到tabBar頁面
2.wx.navigateTo和wx.redirectTo允許跳轉時路徑帶參數,wx.switchTab跳轉時路徑不可帶參數