1 |
"use client"; |
2 |
|
3 |
import { useRouterContext } from "@/contexts/RouterContext"; |
4 |
import { useRouter as useNextRouter } from "next/navigation"; |
5 |
|
6 |
export default function useRouter() { |
7 |
const { isChanging, setIsChanging } = useRouterContext(); |
8 |
const router = useNextRouter(); |
9 |
|
10 |
return { |
11 |
prefetch: router.prefetch, |
12 |
back: router.back, |
13 |
push(href, options) { |
14 |
if (!isChanging) { |
15 |
setIsChanging(true); |
16 |
} |
17 |
|
18 |
router.push(href, options); |
19 |
}, |
20 |
forward: router.forward, |
21 |
refresh: router.refresh, |
22 |
replace: router.replace, |
23 |
} satisfies typeof router; |
24 |
} |