Ionic 4:硬件后退按钮重新加载应用程序 [英] Ionic 4: Hardware Back Button Reloading Application

查看:91
本文介绍了Ionic 4:硬件后退按钮重新加载应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理项目并陷入问题:

硬件后退按钮重装应用程序(我在此应用程序中使用的是Angular Router).

Hardware Back Button Reloading Application (I am using Angular Router in this application).

我退出应用程序的代码:

My Code to Exit Application:

  ionViewDidEnter(){
      this.subscription = this.platform.backButton.subscribe(()=>{
          navigator['app'].exitApp();
      });
  }

  ionViewWillLeave(){
        this.subscription.unsubscribe();
  }

虽然逻辑相同,但可以在其他应用程序中使用.但在此应用程序中,重新加载应用程序不会退出它.

While same logic Working in other applications. but in this application its reloading the application not exiting it.

P.S:我也尝试过将它放入platform.ready(),但是没有运气.

P.S: i have also tried it to put in platform.ready() but no luck.

推荐答案

已解决:

提及具有历史记录,可导致应用程序在根页面上自行重新加载.我能够通过清除历史记录来解决此问题.

As Mention by @rtpHarry template of SideMenu / Tabs have History which leads application to Reload it self on root page. i was able to solve this by clearing History.

ionViewDidEnter(){
  navigator['app'].clearHistory();    
}

只需清除根目录上的

即可清除历史记录,并且硬件后退"按钮将关闭应用程序,而不是重新加载它.

on Your Root Page just Clear your history and your Hardware Back Button will close the Application instead of Reloading it.

这篇关于Ionic 4:硬件后退按钮重新加载应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆