要在 Ionic 4 中控制的 android 默认后退按钮

标签 android angular ionic-framework ionic4

我使用 ionic 4 创建了一个应用程序,我需要控制后退按钮。我使用了以下代码

this.backButtonSubscription = 
this.platform.backButton.subscribeWithPriority(1, async  () => {
    if (this.router.url === '/registration') {
        navigator['app'].exitApp();
    }
});

这个订阅事件只对根页面起作用,对其他页面不起作用。

我想控制特定页面上的后退按钮以显示警报和其他内容,但现在当单击 Android 设备中的硬件后退按钮时,它会转到上一页。

最佳答案

下面的代码对我来说绝对没问题。

app.component.ts 中的 initializeApp() 方法中

initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleLightContent();
      this.splashScreen.hide();
      this.platform.backButton.subscribeWithPriority(9999, () => {
        if(this.router.url !== '/login') {
          // Back button controls when user is not in Login Page
        } else {
          navigator['app'].exitApp();
        }
      });
    });
  }

关于要在 Ionic 4 中控制的 android 默认后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58377926/

相关文章:

javascript - Node.JS 无法安装 ionic

javascript - ng-model 值没有通过 ng-repeat 传递

android - 应用程序在后台运行超过 10 分钟后 Websocket 关闭。 ( native react )

Angular - 使用子路由延迟加载模块内部模块

javascript - nativeElement 对象,DOM 操作

javascript - 类型 'void' 没有属性 'blob' 并且没有字符串索引签名

angular - ionic 无效包名称 __ngcc_entry_points__.json

Android SQLite 使用 db.query() 进行 JOIN 而不是 rawquery()

android - 读取文本外观属性

用于检测移动浏览器屏幕宽度的 Javascript?