In this lab, you'll be utilizing React Router to create a multi page app. Two json files have been provided for you in the src/data folder. React Router has been installed in this project for you. This lab was built with functional components.
forkandclonethis repositorycdinto the repo directorynpm iornpm installto install our dependenciesnpm startto spin up our app
- You must have a page to display when your app loads. The
urlfor this component should be/. - You must have a page to display all games. The
urlfor this component should begames. - You must have a page to display all genres. The
urlfor this component should begenres. - You must have a page to display the details about a game. The
urlfor this component should begames/:game_id. - Your app must be styled
-
Set up your
BrowserRouterin theindex.jsfile. -
Create a
Homecomponent. This component can display anything you'd like. -
Create a
Gamescomponent. Load yourgames.jsonfile into this component. UseuseEffectanduseStateto set the items inside ofgames.jsonto state. Map through your games in state and display them on the page. -
Create a
Genrescomponent. Import thegenres.jsonfile into this component. UtilizeuseEffectanduseStateto set the list of genres to state. -
Create a
GameDetailscomponent that has a more detailed view of a game. You'll want to capture theidin the url bar. Set up some state for this component that looks like the following:const [gameId, setGameId] = useState('') // should be the id in the url bar, const [game, setGame] = useState(null) // Should be null to start and later becomes an object with the selected game.
- You'll want to access get the
idfrom React Router'suseParamshook. - Add a
useEffectto this component. You should use ahigher order array methodto find a movie where the id matches what is in state. You may need to parse the id into an integer. - Display the selected movie in this component.
- You'll want to access get the
-
In
App.js:- Import the provided
Navcomponent and add it to yourApp.js. This component should be used before any routes. NOTE: This component will not work until after you've set upBrowserRouterin theindex.jsfile. - Set up a
<Routes/>for your routes. - Add in the routes for each page according to the requirements above.
- Don't forget to import
RoutesandRoute:import { Routes, Route } from 'react-router-dom'
- Import the provided
-
Style your app! Create a
cssfile in thestylesfolder.
