Wx.switchTab failure

< H1 > wx.switchTab failure < / H1 > < hr >

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": ""
      }
    ]
  }
}
Oct.19,2021

switchTab the url of the jump is the relative address relative to the current page. I understand that the onLaunch and onShow of .. / home/index


app.js register the page only after execution, so you cannot jump at this time, you can put it on the startup page, or setTimeout

in app.js.
Menu