Files
pos/resources/js/admin/tailadmin/hooks/useGoBack.ts
2026-03-06 03:26:11 +07:00

18 lines
385 B
TypeScript

import { useNavigate } from "react-router-dom";
const useGoBack = () => {
const navigate = useNavigate();
const goBack = () => {
if (window.history.state && window.history.state.idx > 0) {
navigate(-1); // Go back to the previous page
} else {
navigate("/"); // Redirect to home if no history exists
}
};
return goBack;
};
export default useGoBack;