这种方式跳转到tabBar页面,并关闭其他所有非tabBar页面
使用这种方式跳转需要事先在app.json中定义好tabBar,如示例3-11所示
app.json
------------------------------
{
"pages":[
"pages/sample/sample",
"pages/index/index",
"pages/navigate/navigate",
"pages/redirect/redirect",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
},
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/logs/logs",
"text": "其他"
}
]
}
}
-------------------------------------------------------------------------------
sample.wxml
-------------------------
<navigator open-type='switchTab' url='/pages/index/index'>
跳转到其他tab
</navigator>
<button bindtap='switchTab'>单击按钮,执行wx.switchTab,跳转到其他tab</button>
-----------------------------------------------------------------------------------
sample.js
-----------------------------
Page({
...省略其他代码
switchTab: function(){
wx.switchTab({
url: '/pages/index/index',
})
}
})
示例3-11中,首先在app.json的tabBar配置项中配置好index页和logs页,并且在pages配置项中设置sample为首页
然后在sample页面中单击“跳转到其他tab”链接或按钮跳转到index页
需要注意的是,通过switchTab的方式跳转页面,url上不能带参数