Reset a stack history of an Ionic 3 tab

纵饮孤独 提交于 2020-01-05 07:52:09

问题


When playing with tabs, I take an example of an ionic app with 2 tabs (tab1 and tab2). With tab1 I can go to tab1->page1->page2 (through the navigation). But the crucial scenario for is that when I click away from my current tab(tab1) to tab2 and come back to click on tab1 I get page2 in front of me but I need to get the stack reset and get tab1 page.


回答1:


If you only have a small set of pages that you are working with you can hook into the lifecycle hook for the view leave and trigger a pop to the root.

  ionViewDidLeave() {
    this.navCtrl.popToRoot();
  }



回答2:


The answer I find till now, especially with few number of pages is to implement that hook:

 ionViewDidLeave(){
    this.navCtrl.popToRoot();
  }

Some other solution also worked for me:

this.navCtrl.setRoot(MyPage);


来源:https://stackoverflow.com/questions/47857967/reset-a-stack-history-of-an-ionic-3-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!