We need our GalleryNavigation component with all its links to show on every page, not just the /galleries route. We also want to apply visual feedback to show which route is active by using NavLink's .active class. The best solution is to create a shared layout that wraps all pages and renders GalleryNavigation globally.
Layout component that renders GalleryNavigation and an Outletchildren arrayNavLinks by importing a CSS file and targeting .activeAdd this to the top of your App.jsx file:
import { Outlet } from 'react-router-dom';
function Layout() {
return (
<div className="page-wrapper">
<GalleryNavigation galleries={harvardArt.records} />
<main>
<Outlet />
</main>
</div>
);
}
Use the layout as a wrapper, and nest the homepage and 404 routes as children. Remove the /galleries route entirely.
const router = createBrowserRouter([
{
element: <Layout />,
children: [
{
path: '/',
element: (
<>
<h2>Harvard Art Museum</h2>
<p>Look, but Don't Touch. Please select a Gallery in the navigation bar.</p>
</>
)
},
{
path: '*',
element: <h2>Page Not Found</h2>
}
]
}
]);
Now GalleryNavigation appears on every route!
Create a new file: src/components/GalleryNavigation/GalleryNavigation.css
.active {
font-weight: bold;
}
Then import it into GalleryNavigation.jsx:
import './GalleryNavigation.css';
You now have a centralized layout and consistent navigation across pages. Styling active links improves usability and reinforces routing behavior.
Imagine a museum where every exhibit room includes the same map at the entrance. That map lets you jump to any other room, and the current one is highlighted. That's exactly what this layout and NavLink pattern accomplish.