init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user