mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
19 lines
437 B
TypeScript
19 lines
437 B
TypeScript
|
|
import { useNavigate, useLocation } from 'react-router-dom';
|
||
|
|
|
||
|
|
const useOriginNavigate = () => {
|
||
|
|
const _navigate = useNavigate();
|
||
|
|
const location = useLocation();
|
||
|
|
|
||
|
|
const navigate = (url?: string | null, opts = {}) => {
|
||
|
|
if (!url) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const path = location.pathname.match(/^\/[^/]+\//);
|
||
|
|
_navigate(`${path ? path[0] : '/chat/'}${url}`, opts);
|
||
|
|
};
|
||
|
|
|
||
|
|
return navigate;
|
||
|
|
};
|
||
|
|
|
||
|
|
export default useOriginNavigate;
|