Curriculum
Course: React
Login

Curriculum

React

Text lesson

React Router

Create React App does not include page routing by default; React Router is the most popular solution for this purpose.

Add React Router

To add React Router to your application, execute the following command in the terminal from the root directory:

npm i -D react-router-dom

Note: This tutorial uses React Router v6. If you’re upgrading from v5, you’ll need to use the @latest flag.

npm i -D react-router-dom@latest

Folder Structure

To set up an application with multiple page routes, start by organizing the file structure. Inside the src folder, create a pages directory with the following files:

  • src/pages/Layout.js
  • src/pages/Home.js
  • src/pages/Blogs.js
  • src/pages/Contact.js
  • src/pages/NoPage.js

Each file will contain a basic React component.