Files
react-gantt/demos/common/Router.jsx
Marta Kowalska bb81e7a336 v2.4.3
2025-12-22 20:22:30 +00:00

34 lines
855 B
JavaScript

import { useEffect, useRef } from 'react';
import {
Routes,
Route,
Navigate,
useLocation,
useNavigate,
} from 'react-router-dom';
import { links } from '../routes';
export default function Router({ onRouteChange }) {
const location = useLocation();
const navigate = useNavigate();
const lastRef = useRef(location.pathname);
useEffect(() => {
if (lastRef.current === location.pathname) return;
if (location.pathname === '/') {
navigate('/base/willow', { replace: true });
} else {
onRouteChange(location.pathname);
}
}, [location.pathname, onRouteChange, navigate]);
return (
<Routes>
<Route path="/" element={<Navigate to="/base/willow" replace />} />
{links.map(([path, , Component]) => (
<Route key={path} path={path} element={<Component />} />
))}
</Routes>
);
}