title: My Hardware 'Back Button Action' is not working in Ionic 4
body: <p>I am working in my Ionic 4 app and When the user clicks 2 times on the mobile back button, then it should close the app but this is not happening.</p>
  
  <p>This is my <strong>app.component.ts</strong>:</p>
  
  <pre><code>lastTimeBackPress = 0;
  timePeriodToExit = 2000;
  @ViewChildren(IonRouterOutlet) routerOutlets: QueryList&lt;IonRouterOutlet&gt;;
  
  constructor(){
  this.backButtonEvent();
  }
  
  backButtonEvent() {
      document.addEventListener("backbutton", () =&gt; { 
        this.routerOutlets.forEach((outlet: IonRouterOutlet) =&gt; {
          if (outlet &amp;&amp; outlet.canGoBack()) {
              outlet.pop();
          } else if (this.router.url === '/tabs/tab1') {
            if (new Date().getTime() - this.lastTimeBackPress &lt; this.timePeriodToExit) {
              navigator['app'].exitApp(); //Exit from app
              } else {
              this.presentAlertConfirm();
              this.lastTimeBackPress = new Date().getTime();
            }
            // navigator['app'].exitApp(); // work for ionic 4
          }
        });
      });
    }
  
    async presentAlertConfirm() {
      const alert = await this.alertController.create({
        // header: 'Confirm!',
        message: 'Are you sure you want to exit the app?',
        buttons: [
          {
            text: 'Cancel',
            role: 'cancel',
            cssClass: 'secondary',
            handler: (blah) =&gt; {
            }
          }, {
            text: 'Close App',
            handler: () =&gt; {
              navigator['app'].exitApp();
            }
          }
        ]
      });
  
      await alert.present();
    }
  </code></pre>
  
  <p>This is working when I am on front page(Tab1) and when I am on the other tabs it is not working and not going to the front page.</p>
  
  <p>I think the problem is in my (<code>outlet &amp;&amp; outlet.canGoBack())</code> because this is not working. I am using the tab theme and Can I send the route to the main tab when the user is no other tabs and clicks the hardware back button.</p>
  
  <blockquote>
    <p>I am using Ionic 4 tab theme.</p>
  </blockquote>
  
  <p>Any help is much appreciated.</p>