Files
igny8/frontend/src/hooks/useGoBack.ts
2025-11-09 10:27:02 +00:00

18 lines
381 B
TypeScript

import { useNavigate } from "react-router";
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;