angular - ionic 4 防止/禁用设备硬件后退按钮

标签 angular typescript ionic-framework ionic4 angular-router

我正在为 ionic 4 项目使用 Angular 路由(@angular/router)来禁用 ionic 4 中的设备后退按钮,防止默认不起作用,下面是我的代码

app.component.ts

    this.platform.backButton.subscribe(() => {
        if (this.router.url === '/Login') {
          this.util.presentAppExitAlert();
        } else {
          // event.preventDefault();
          console.log("invoing url ", this.router.url);
        }
      });
    });

我无法在此处禁用设备后退按钮任何帮助

最佳答案

initializeApp() {
    this.platform.ready().then(() => {
      this.platform.backButton.subscribeWithPriority(9999, () => {
        document.addEventListener('backbutton', function (event) {
          event.preventDefault();
          event.stopPropagation();
          console.log('hello');
        }, false);
      });
      this.statusBar.styleDefault();
    });
  }

关于angular - ionic 4 防止/禁用设备硬件后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55274992/

相关文章:

typescript - 更改集合时不会触发 Aurelia CollectionObserver 处理程序

angularjs - 从 angular ionic 应用程序使用山魈发送电子邮件

css - 使用模态和样式的 Ionic 2 登录弹出窗口

angular - 如果元素是动态创建的,以编程方式将 [ngClass] 添加到宿主元素的正确方法是什么?

angular - 用户离线时如何使用 Angular PWA 处理身份验证?

javascript - 使用 Typescript 的属性名称冲突

typescript 中的 Json 属性别名

android - fs-extra:源和目标不能相同。 ( Cordova )

angular - 父/子组件之间使用 RXJS 或 @input/@output 进行通信哪个更好

angular - Angular 5 中可以注册多个拦截器吗?