In this project, you'll build a frontend-only React app that showcases art galleries using data from the Harvard Art Museum API. Users will be able to navigate through galleries and view individual art pieces using React Router. This is great practice for learning routing, data rendering, and basic React architecture.
This setup phase ensures you have all necessary tools and files before you build the app. Here's a simplified whiteboard plan:
App.jsxdata folder and import harvardArt.js seed datanpx tiged appacademy/aa-react18-vite-template art-museum
cd art-museum
npm install react-router-dom
Edit src/App.jsx to render:
function App() {
return <h1>Hello from App</h1>;
}
Then run:
npm run dev
Visit http://localhost:5173. You should see "Hello from App".
App.jsximport { createBrowserRouter, RouterProvider } from 'react-router-dom';
const router = createBrowserRouter([
{
path: '*',
element: <h2>Page Not Found</h2>
}
]);
function App() {
return <RouterProvider router={router} />;
}
export default App;
Inside src, create a folder called data and inside it, create a file called harvardArt.js.
Run this command from the root of your project:
curl https://appacademy-open-assets.s3-us-west-1.amazonaws.com/Modular-Curriculum/content/react-redux/topics/intro-to-react/projects/art-museum/harvardArt.js > src/data/harvardArt.js
Then import the object in App.jsx:
import harvardArt from './data/harvardArt';
console.log(harvardArt);
Check your browser console at http://localhost:5173 to confirm the structure. You’ll use the records and objects fields throughout the project.
You now have a functioning React app with React Router and seed data. This solid foundation will support all future development for the Art Museum Project.
Now that the base routing is set, you need to add a new route for the home page /. This route will display a title and description introducing the user to the Art Museum app.
/<></> or wrapper to return both heading and paragraph/ shows the home page, and unknown paths still show the 404const router = createBrowserRouter([
{
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>
}
]);
This update shows the Home Page when users visit http://localhost:5173 and the 404 for anything else.
This simple route structure allows us to build out each page within the app in a scalable way. In the next phases, we’ll replace inline JSX with full components and add navigation to galleries and individual artwork.
When pasting text with special characters like apostrophes (e.g., Don’t), use ' to avoid JSX parser errors. Example:
<p>Look, but Don't Touch</p>