我想知道当我们单击离子3中的ion-navbar Back Back按钮时,在Ionic 3中单击了哪个函数。我想在硬件返回按钮上调用相同的功能。
您可以使用平台服务的 dogensebackButtonAction 。您可以覆盖 app.component.ts 的下面的硬件返回按钮操作。切记在Platform.ready()
之后致电registerBackButtonAction
。
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();
}
});
});
}
}
希望这对您有帮助。