mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-10 08:18:12 +03:00
Try out history safe-go-back
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user