CLOSE ✕
Get in Touch
Thank you for your interest! Please fill out the form below if you would like to work together.

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form

Set up navigation using React Router DOM

Neelanshi Sharma
|
React
|
Mar 1, 2021

React router is a library that allows you to handle routes in a web app, using dynamic routing. Dynamic routing takes place as the app is rendering on your machine, unlike the old routing architecture where the routing is handled in a configuration outside of a running app.

React router implements a component-based approach to routing. It provides different routing components according to the needs of the application and platform.

React Router DOM is DOM bindings for the React Router, or in simpler terms React Router for websites.

Installation

React Router can be installed using the npm cli utility:

>npm install react-router-dom

Implementation

1. Set up your app to work with React Router by wrapping the app in <BrowserRouter> element. Everything that gets rendered goes inside the <BrowserRouter> element tag. We will create four components. Inside <Switch>, which is basically a switch case in react, define all routes for your website and the components they are directed to.

App.js

This can also be done in the followinf way:

<Route path="/" component={Home}/>

2. Using <NavLink> you can wrap and make that component point to the specified route defined in App.js through 'to' property.

And there you go!

Neelanshi Sharma
Neelanshi is a mobile and web developer. She is a computer science major from Banasthali Vidyapith, India.

Recent Blog Posts

Lets Work Together
Contact Me