Files
react-gantt/demos/common/Router.jsx
Marta Kowalska 80ca059fb8 v2.3.1
2025-10-22 08:13:59 +00:00

32 lines
747 B
JavaScript

import { useEffect } 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();
useEffect(() => {
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>
);
}