12. Multipage Apps with React Router
Activity 12.1: Creating a Basic Three-Page Website
Solution:
Perform the following steps to complete this activity:
- Create a new React project via
npx create-react-app
as explained in Chapter 1, React: What & Why?. Then, install the React Router library by runningnpm install react-router-dom
inside the project folder. - For the three required pages, create three components: a
Welcome
component, aProducts
component, and aProductDetail
component. Store these components in files inside thesrc/routes
folder since these components will only be used for routing.
For the Welcome
component, enter the following code:
// src/routes/Welcome.js function Welcome() { return ( <main> <h1>Welcome to our shop!</h1> <p> Please explore our products or share...