How to Install and Setup React Router in ReactJS

Learn to install and setup React Router

Picture of Nsikak Imoh, author of Macsika Blog

The first thing we want to do is setup our project to run React Router.

  • Step 1: Install create-react-app

    Run the code below in the terminal.

    npx create-react-app react-router-demo
    Import into project.

    This will generate a project with several boilerplate codes which comes with the React library.

  • Step 2: Install react-router package

    Using npm package manager:

    npm install react-router

    Using yarn manager:

    yarn add react-router
    Install React Router Package using npm and yarn package managers.

This should install the latest version of React Router, which is currently React Router 6.

To see the version installed, check the package.json file in the react project.

Next Tutorial — How to Configure Routes in ReactJS with React RouterGet the Complete Code of React Router Tutorials on Github.

Connect with me.

Need an engineer on your team to grease an idea, build a great product, grow a business or just sip tea and share a laugh?