better-auth/apps/web/modules/shared/hooks/router.ts
 Илья Шалонин 8538ab969a first
2025-10-29 13:43:43 +05:00

32 lines
772 B
TypeScript

import { useRouter as useBaseRouter, usePathname } from "next/navigation";
import NProgress from "nprogress";
import { useCallback, useEffect } from "react";
export const useRouter = () => {
const router = useBaseRouter();
const pathname = usePathname();
useEffect(() => {
NProgress.done();
}, [pathname]);
const replace = useCallback(
(href: string, options?: Parameters<typeof router.replace>[1]) => {
href !== pathname && NProgress.start();
router.replace(href, options);
},
[router, pathname],
);
const push = useCallback(
(href: string, options?: Parameters<typeof router.push>[1]) => {
href !== pathname && NProgress.start();
router.push(href, options);
},
[router, pathname],
);
return {
...router,
replace,
push,
};
};