我想知道在离子3中默认单击离子导航栏后退按钮时调用了哪个函数。我想在硬件后退按钮上单击调用相同的功能。
你可以使用registerBackButtonAction的Platform Service。您可以在app.component.ts中覆盖硬件后退按钮操作,如下所示。记得在registerBackButtonAction
之后打电话给Platform.ready()
。
import { Platform, App } from 'ionic-angular';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
constructor(public platform: Platform, private app: App) {
this.platform.ready().then(() => {
this.platform.registerBackButtonAction(() => {
let nav = this.app.getActiveNav()
if (nav.canGoBack()) {
// If there are pages in navigation stack go one page back
// You can change this according to your requirement
nav.pop();
} else {
// If there are no pages in navigation stack you can show a message to app user
console.log("You cannot go back");
// Or else you can exit from the app
this.platform.exitApp();
}
});
});
}
}
希望这会帮助你。