当前位置:网站首页>The route of wechat applet jumps again without triggering onload

The route of wechat applet jumps again without triggering onload

2022-07-05 06:26:00 Heerey525

situation :

1、 from index Page Jump (wx.navigateTo) To add page , The first time will enter add page onLoad, But the second time from index Page Jump (wx.navigateTo) To add page , Will not enter add Page onLoad;
2、 from add Page Jump (wx.redirectTo) To index page , Will not enter the index page onLoad

reason :

When you first enter a page , Will enter the page onLoad, But jump around , In fact, the route is not destroyed , The page already has a routing stack , So it's cached , Will not enter again onLoad

resolvent :

1、 stay onShow Enter to get the routing parameters

onShow: function () {
    
    //  Get the page stack of the current applet  
    let pages = getCurrentPages(); 
    //  The page with the largest index in the array -- Current page  
    let currentPage = pages[pages.length-1]; 
    //  Print out... In the current page  options 
    console.log(currentPage.options)
}

2、switchTab Of success Add in callback onLoad Method

wx.switchTab({
    
    url: '../index/index',
    success: function(e) {
    
      var page = getCurrentPages().pop();
      if (page == undefined || page == null) return;
      page.onLoad();
    }
})

Reference material :
Applet framework / Logic layer / Page routing
Applet usage wx.navigateTo Jump to the page , On the page onload Don't execute ?
Wechat applet switchTab New page after jump onload Problems that don't trigger

原网站

版权声明
本文为[Heerey525]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050623068692.html