路由问题(设置引导页面跳入tabBar出现switchTab:fail page
发布于 6 年前 作者 jun62 6671 次浏览 来自 问答
  • 通过在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的执行顺序。

2 回复

执行onlunch时,配置文件应该是已经执行了,可以试试使用/pages/home/home

回到顶部