Files
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

28 lines
682 B
TypeScript
Executable File

import {
createPath,
NavigateFunction,
resolvePath,
useLocation,
useNavigate as useRouterNavigate
} from 'react-router-dom';
import {useCallback} from 'react';
export function useNavigate() {
const routerNavigate = useRouterNavigate();
const location = useLocation();
return useCallback(
(to, options) => {
// prevent duplicates in history when navigating to the same url
const replace =
createPath(location) === createPath(resolvePath(to, location.pathname));
routerNavigate(to, {
...options,
replace: options?.replace !== false && replace,
});
},
[routerNavigate, location]
) as NavigateFunction;
}