title: Handling back button in Ionic 3 with tabs
body: <p>This <a href="https://stackoverflow.com/questions/42151944/ionic-2-how-to-handle-the-hardware-back-button-which-checks-confirmation-of-exit">question and its answers</a> <strong>(copied below)</strong> provide a solution for handling the back button in Ionic, but that solution only works when other pages are pushed directly from <code>app.component</code>, in which case calling <code>canGoBack</code> and <code>getActive()</code> on <code>this.nav</code> works correctly because other pages have been pushed using <code>this.nav.push</code> in <code>app.component</code>.</p>
  
  <p>However if a page is pushed from one of the pages in the tabs (lets call it <code>page1</code>), i.e. by calling <code>this.navCtrl.push()</code> in <code>page1</code>, then <code>this.nav.canGoBack()</code> in <code>app.components</code> still resolves to false because the push happened using the <code>page1's</code> <code>this.navCtrl.push()</code> not app.component's <code>this.nav.push()</code>.</p>
  
  <p>How can I detect inside <code>app.components</code> if a page was pushed from any of pages in the tabs?</p>
  
  <pre><code> platform.registerBackButtonAction(() =&gt; {
  
          if(this.nav.canGoBack()){
            this.nav.pop();
          }else{
            if(this.alert){ 
              this.alert.dismiss();
              this.alert =null;     
            }else{
              this.showAlert();
             }
          }
        });
      });
  
    }
  </code></pre>