How to implement React Routing

Piyush Garg
Daily Programmer
Published in
1 min readApr 21, 2020

--

In this article, I will be explaining how to implement routing in react app in very simple steps.

Step 1: Install react-router-dom

npm install react-router-dom

Step 2: Importing react-router-dom in our project

In the above code, we have wrapped our <App/> component with <BrowserRouter /> which enables us to use Html 5 history API.

Step 3: Implement Routing

In app.js we need to implement switch cases with various routes as shown in the above code.

Each Route component needs two mandatory props and that is the path and the component to render.

Congratulations, you have now implemented routing in your react app.

--

--

Piyush Garg
Daily Programmer

21 years old application and web developer. Certified in C, C++, And Java. Completed IT Trainings in Web Development, Javascript, MERN and web Designs, Android