/react-router-v5

Project #49 of Codecademy's Full Stack Engineer Career Path

Primary LanguageJavaScriptMIT LicenseMIT

React Router Tutorial Exercise

Project #49 from Codecademy's Full Stack Engineer Career Path

By Anton Vlasenko (AntonV0)

Project Outline

This project introduced me to routing - using the current browser URL to determine what content to show a user. React Router v5 was installed, as v6 introduced changes that break the starter code.

What I Learned

  • Installing react-router-dom from the terminal
  • Enabling routing by wrapping contents in the BrowserRouter component
  • Adding routes with the Route component
  • Static routes (without URL parameters, e.g. /users)
  • Dynamic routes (with URL parameters, e.g. /users/:userId)
  • Using the useParams hook to access the values of URL parameters
  • Declaratively redirecting users by rendering the Redirect component
  • Imperatively redirecting users by accessing the history object via the useHistory hook and calling its methods (goForward, goBack, push)
  • Accessing the value of query parameters using the useLocation hook

Please note that in each project, the first commit is always the starter code provided by Codecademy.