0

I have used this.navCtrl.push() to navigate to a new page on click of a button. It creates a default back button clicking which takes me back to the previous page. I want to navigate to another page on click of the back button. How can I do that ?

I have tried this but it doesn't work :

constructor(public navCtrl: NavController, public navParams: NavParams,public platform: Platform) {
  platform.ready().then(()=>{
       platform.registerBackButtonAction(()=>this.myHandlerFunction());
});
  }
myHandlerFunction(){
this.navCtrl.setRoot(VesselsearchPage);

}

1 Answers1

1

inject Platform from 'ionic-angular' and then register a new handler to the back button action:

import { Platform } from 'ionic-angular';

constructor(private platform: Platform) { }

ionViewWillEnter(): void {
    this.platform.registerBackButtonAction(() => this.backButtonFunc());
}

private backButtonFunc(): void {
     // do something 
}
Ali Mustafa
  • 115
  • 4