离子 - 处理NavBar后退按钮?

Con*_*ady 2 typescript ionic-framework

通过Ionic中的硬件按钮进行处理的所有解决方案都使用了以下方法:

 platform.ready().then(() => {
  platform.registerBackButtonAction(() => {
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否有办法处理导航栏中显示的后退按钮,因为当我在Android中按下它时似乎没有触发.我试图找到的所有解决方案都参考了顶部的代码,它们似乎只适用于硬件按钮.

Pra*_*ant 6

我已经使用此代码在ionic-3中实现了它.

   import { Navbar } from 'ionic-angular';

   export class myCustomClass {

   @ViewChild(Navbar) navBar: Navbar;

   ...

   ionViewDidLoad() {
       this.setBackButtonAction()
   }

   //Method to override the default back button action
   setBackButtonAction(){
     this.navBar.backButtonClick = () => {
     //Write here wherever you wanna do
      this.navCtrl.pop()
     }
   }
Run Code Online (Sandbox Code Playgroud)