first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
32
apps/web/modules/shared/hooks/router.ts
Normal file
32
apps/web/modules/shared/hooks/router.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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,
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue