In this lab, you will create a simple Client-Side routing application with React Router.
- Practice building an application with React Router
- Access routes using a Navbar with matched routes
- Visit different "views" in the application by accessing different routes
In this lab we are going to build out an application that has routes for a Home Page, Actors Page, Movies Page and Directors Page. Our goal is to provide routes and links for these 4 pages.
This is what our app should look like when we are done with this lab:
Let's work through this one component at a time
Our src
folder contains the following:
src/
├── data.js
├── index.js
|-- containers/
| |-- App.js
└── components/
├── Actors.js
├── Directors.js
├── Home.js
├── Movies.js
└── NavBar.js
All of the file and module imports are done for you, so you just need to focus on the JSX for these components.
Our index.js
file is completed for us. It loads App as the top level component.
This file contains seed data for Actors, Movies & Directors
This component already contains a Router
wrapper where we'll include our
particular routes. App should render our Navbar
and 4 React Router Route
components with paths to /, /movies, /directors & /actors and has a props of
the corresponding component. When a user visits the root url, they should see
the Home component. Since a Router
wrapper can only wrap one element, use a
div
to wrap the Navbar
and routes. This allows us to apply a CSS class at the App
component level.
This component needs to render 4 <NavLink>
components. They will be for /,
/movies, /directors, /actors <-- in this order(test checks for this).
This component should render the text Home Page
.
This component should render the text Movies Page
, and make a new <div>
for
each movie. The <div>
should contain the movie's title, time and an <ul>
for
each genre.
This component should render the text Directors Page
, and make a new <div>
for each director. The <div>
should contain the director's name and an <ul>
for each of their movies.
This component should render the text Actors Page
, and make a new <div>
for
each actor. The <div>
should contain the actor's name and an <ul>
for each
of their movies.
React Router React Router Tutorial
View React Components As Routes Lab on Learn.co and start learning to code for free.