我正在使用Ionic和React来开发应用程序。我找不到任何关于如何处理硬件后退按钮点击以及如何退出应用程序的文档。有没有关于这个的文档或教程?
import React, { useEffect } from "react";
import { Plugins, Capacitor } from "@capacitor/core";
Run Code Online (Sandbox Code Playgroud)
useEffect(() => {
if (Capacitor.isNative) {
Plugins.App.addListener("backButton", (e) => {
if (window.location.pathname === "/") {
// Show A Confirm Box For User to exit app or not
let ans = window.confirm("Are you sure");
if (ans) {
Plugins.App.exitApp();
}
} else if (window.location.pathname === "/YourFirstPageRoute") {
// Show A Confirm Box For User to exit app or not
let ans = window.confirm("Are you sure");
if (ans) {
Plugins.App.exitApp();
}
}
});
}
}, []);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2387 次 |
| 最近记录: |