Files
History-user/src/hooks/useGoBack.ts
T
2026-04-28 09:27:54 +07:00

18 lines
357 B
TypeScript

import { useRouter } from "next/navigation";
const useGoBack = () => {
const router = useRouter();
const goBack = () => {
if (window.history.length > 1) {
router.back(); // Navigate to the previous route
} else {
router.push("/"); // Redirect to home if no history exists
}
};
return goBack;
};
export default useGoBack;