What is React Router

What is React Router

How To Navigate Between Components in Your React App

React Router is a standard library for routing in React that enables you to switch between views in your application.

How to install React Router

First you would need to create a react app

how to install react router.png

If you are writing a React Native application, replace -dom with -native

how to install react router (1).png

In your App.js file, import the router

how to import and use react router in your application.png

BrowserRouter is the parent component that contains the other components, it keeps your UI in sync with the URL.

Switch is used to render only the first route that matches the location.

Route is used to conditionally show component that renders some UI when its path matches the current URL.

To link to other paths in application or website use the link component, this is used to navigate to different routes in your application just like the HTML anchor tag

how to link to other paths in your application.png

And boooom! You can successfully switch between views and also click on links.