wx.switchTab失效
我在app.js的onLaunch
当中wx.getStorage
获取cookie字段,如果存在则直接通过wx.switchTab
跳转到主页。但是失效,并不会跳转,不过switchTab
的success
回调会执行。
app.js onLaunch
onLaunch: function() {
let that = this;
// 展示本地存储能力
wx.getStorage({
key: 'cookie',
success: function(res) {
that.globalData.cookie = res.data
wx.switchTab({
url: '/pages/home/index',
success:res=>{
console.log(res);
},
fail:err=>{
console.log(err)
}
})
}),
app.json
{
"pages": [
"pages/login/login",
"pages/home/index",
"pages/me/index",
"pages/news/index",
"pages/home/pages/leave/index",
"pages/home/pages/count/index",
"pages/home/pages/count/pages/next/next",
"pages/home/pages/profile/index"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"tabBar": {
"color": "#a9b7b7",
"selectedColor": "#11cd6e",
"borderStyle": "white",
"list": [
{
"selectedIconPath": "images/index/index.png",
"iconPath": "images/index/index.png",
"pagePath": "pages/home/index",
"text": "首页"
},
{
"selectedIconPath": "images/index/message.png",
"iconPath": "images/index/message.png",
"pagePath": "pages/news/index",
"text": "消息中心"
},
{
"selectedIconPath": "images/index/user.png",
"iconPath": "images/index/user.png",
"pagePath": "pages/me/index",
"text": "我"
}
]
}
}
switchTab
跳转的url
是相对当前 page 的相对地址,我理解可能是../home/index