先用@HostListener('document:ionBackButton', ['$event']) 监听安卓返回键
用window.location 判断当前页面是否需要后退
window.history.back(); js回退页面
ionic里 退出app方法 this.appMinimize.minimize();
下面贴上全部代码
@HostListener('document:ionBackButton', ['$event'])
private overrideHardwareBackAction($event: any) {
$event.detail.register(100, async () => {
// Do what you want
// 安卓返回键问题
let url = window.location.href;
console.log("返回键盘");
console.log(url,url.indexOf("tabs"));
if(url.indexOf("tabs") != -1) {
this.appMinimize.minimize();
} else {
console.log("退到上一级");
window.history.back();
}
// this.appMinimize.minimize();
// this.router.navigateByUrl('相应路径');
});
}