import { useState, useEffect } from 'react'; import { Outlet, useLocation } from 'react-router-dom'; import Sidebar from '@/components/layout/Sidebar'; import Header from '@/components/layout/Header'; import { ErrorBoundary } from '@/App'; export default function Layout() { const { pathname } = useLocation(); const [sidebarOpen, setSidebarOpen] = useState(false); // Close sidebar on route change (mobile navigation) useEffect(() => { setSidebarOpen(false); }, [pathname]); return (
{/* Fixed sidebar */} setSidebarOpen(false)} /> {/* Main area offset by sidebar width on desktop, full-width on mobile */}
setSidebarOpen(true)} /> {/* Page content — ErrorBoundary keyed by pathname so the nav shell survives a page crash and the boundary resets on route change */}
); }