一.解決方案
①只要將首頁index目錄不加入app.json中tabBar的list列表里就好了
②在app.json的pages里將index目錄位置放在第一個,也就是小程序剛進入的首頁位置
③通過wx.switchTab方法跳轉(zhuǎn)到具有tabBar功能的頁面,就可以啦
wx.switchTab({url: '../home/home'})
二.demo演示
1.首頁index的wxml代碼如下
<view class="container">
<view>
<button class="gotoBtn" bindtap="gotoBtnView"> 跳轉(zhuǎn) </button>
</view>
</view>
首頁index的js代碼如下:
Page({
data: {
},
//事件處理函數(shù)
gotoBtnView: function() {
wx.switchTab({
url: '../home/home'
})
},
})
2.將index放首頁位置,將需要tabbar功能的頁面(home和myInfo)添加到list中
app.json代碼如下
{
"pages": [
"pages/index/index",
"pages/home/home",
"pages/myInfo/myInfo"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"tabBar": {
"list": [
{
"pagePath": "pages/home/home",
"text": "home",
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "pages/myInfo/myInfo",
"text": "myInfo",
"iconPath": "",
"selectedIconPath": ""
}
]
},
"sitemapLocation": "sitemap.json"
}
3.測試
1.首頁如下圖所示,沒有tabBar功能,點擊跳轉(zhuǎn)

index.png
2.跳轉(zhuǎn)后的home頁面(具有tabBar功能),可以使用tabBar切換頁面了

home.png

myInfo.png
成功?。?!