我想知道在默认情况下,在离子3中单击离子导航条返回按钮时调用哪个函数。我想在硬件上调用相同的函数,单击后退按钮。
发布于 2019-03-10 06:44:18
您可以使用registerBackButtonAction of 平台服务。您可以覆盖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();
}
});
});
}
}希望这能帮到你。
https://stackoverflow.com/questions/55081560
复制相似问题