I get the cookie field in onLaunch of app.js wx.getStorage , and jump to the home page directly via wx.switchTab if it exists. However, if it fails, it will not jump, but the success callback of switchTab will be executed.
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": "-sharpfff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"tabBar": {
"color": "-sharpa9b7b7",
"selectedColor": "-sharp11cd6e",
"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": ""
}
]
}
}
