- 通过在app.js中判断本地存储token,跳转到引导页(非tabBar页)面或home(tabBar页)页面
- app.js app.json
- 提供一个最简复现 Demo
备注:“pages/getiphone/getiphone”,为引导页面(初始页)
app.json
{
“pages”:[
“pages/getiphone/getiphone”,
“pages/home/home”,
“pages/logs/logs”,
],
“tabBar”: {
“list”: [
{
“selectedIconPath”: “imgs/hometap.png”,
“iconPath”: “imgs/home.png”,
“pagePath”: “pages/home/home”,
“text”: “首页”
},
{
“selectedIconPath”: “imgs/mytap.png”,
“iconPath”: “imgs/my.png”,
“pagePath”: “pages/logs/logs”,
“text”: “个人中心”
}
]
}
app.js中onLaunch 对本地缓存判断
onLaunch: function() {
success(res) {
console.log(‘本地存储是’)
console.log(res)
if (res) {
mythis.globalData.token = res.data
wx.switchTab({
url: ‘…/home/home’
})
if (mythis.userInfoReadyCallback) {
mythis.userInfoReadyCallback(res.data)
}
} else {
//json配置非引导"pages/getiphone/getiphone",页采用下面跳转
// wx.navigateTo({
// url: ‘…/getiphone/getiphone’,
// })
}
},
}
问题:
当本地缓存中有数据直接进入
wx.switchTab({
url: ‘…/home/home’
})
报错:switchTab:fail page “home/home” is not found (非必现,多次刷新会出现);
请教:app.js和app.json的执行顺序。