Try out history safe-go-back

This commit is contained in:
zkldi
2021-11-24 02:53:55 +00:00
parent a620bf37b1
commit 218dcfe7a0
6 changed files with 19 additions and 10 deletions
+9
View File
@@ -1,4 +1,5 @@
import toast from "react-hot-toast";
import { useHistory } from "react-router-dom";
import {
APIPermissions,
ChartDocument,
@@ -188,3 +189,11 @@ export function WrapError<T>(fn: () => T, errMsg: string) {
export function Sleep(ms: number) {
return new Promise<void>(resolve => setTimeout(() => resolve(), ms));
}
export function HistorySafeGoBack(history: ReturnType<typeof useHistory>) {
if (history.length === 1) {
history.replace("/");
} else {
history.goBack();
}
}