首页 > 解决方案 > 如何仅禁用特定页面的硬件后退按钮

问题描述

我对如何禁用后退按钮硬件有疑问。我只希望它在我的应用程序的主页上工作,而不是在其他页面上工作。当您在主页上时它运行良好,但也适用于打开的所有其他页面。我希望用户能够在除主页之外的所有页面上使用后退按钮。这是我的代码

`deactivateBackButton()
this.subscribe = this.platform.backButton.subscribeWithPriority(666666,()=>{
if (this.constructor.name == "HomePage") {
if (window.confirm("Do you want to exit app")) {
navigator["app"].exitApp();
 }
}
});
}`

标签: androidangularionic-framework

解决方案


在其他页面上:

activateBackButton()
    this.subscribe =  this.platform.backButton.subscribeWithPriority(666666,()=>{
          if (this.constructor.name != "HomePage") {
             // go back to previous page
          }
     });
  }

推荐阅读