Handling back button in Ionic 3 with tabs

瘦欲@ 提交于 2019-12-24 05:06:25

问题


This question and its answers (copied below) provide a solution for handling the back button in Ionic, but that solution only works when other pages are pushed directly from app.component, in which case calling canGoBack and getActive() on this.nav works correctly because other pages have been pushed using this.nav.push in app.component.

However if a page is pushed from one of the pages in the tabs (lets call it page1), i.e. by calling this.navCtrl.push() in page1, then this.nav.canGoBack() in app.components still resolves to false because the push happened using the page1's this.navCtrl.push() not app.component's this.nav.push().

How can I detect inside app.components if a page was pushed from any of pages in the tabs?

 platform.registerBackButtonAction(() => {

        if(this.nav.canGoBack()){
          this.nav.pop();
        }else{
          if(this.alert){ 
            this.alert.dismiss();
            this.alert =null;     
          }else{
            this.showAlert();
           }
        }
      });
    });

  }

来源:https://stackoverflow.com/questions/46757910/handling-back-button-in-ionic-3-with-tabs

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