title: On hardware back button check whether any modal is present and dismiss the modal
body: <p>Ionic v4 - On hardware back button I have to check whether any modal is present. If any modal is present then close that modal. If no modal is present then go one page back</p>
  
  <p>I have used below line of code</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>    private backButtonEvent() {
      this.platform.backButton.subscribe(async () =&gt; {
          debugger;
          try {
              let activeModal = await this.modalCtrl.getTop();
              debugger;
              if(activeModal) {
                  activeModal.dismiss();
                  return;
              }
          } catch(ex) { console.log(ex); }
          this.routerOutlet.forEach((ro: IonRouterOutlet) =&gt; {
              if (this.router.url === '/login' || this.router.url === '/home') {
                  if (this.router.url === '/home') {
                      this.common.confirmShow('Exit', 'Do you want to exit the app ?\r\nYou will be logged out after closing the app').then(d =&gt; {
                          if (d == 1) {
                              navigator['app'].exitApp();
                          }
                      }).catch(e =&gt; { console.log(e); });    
                  } else if (this.router.url === '/login') {
                      navigator['app'].exitApp();
                  }
              }
              else if (ro &amp;&amp; ro.canGoBack()) {
                  ro.pop();
              }
          });
      });        
  }
  </code></pre>
  
  <p>Here, it always satisfies the activeModal true</p>