Introduction to React Router
Learn what react-router is and understand how it works behind the scenes.
Introduction to the routing library
There are multiple ways to implement routing in React applications, such as by creating custom hooks. However, this approach is time-consuming, as it requires the creation of separate hooks for individual features.
Instead, we can use a feature-rich library, such as react-router
, which is recommended by the React team. Top companies like Facebook, Netflix, Microsoft, and Discord all use this library.
What is react-router
?
The react-router
is a routing library for React. Official documentation describes it as a fully-featured client-side and server-side routing library for React, a JavaScript library for building user interfaces.
We can use react-router
on the web, NodeJS, and React Native. It has several advantages:
- The
react-router
is mainly used to make single-page applications (SPA). It maintains the behavior and structure of the web application. - It allows us to use different browser functionalities such as refresh, back button, and locate objects.
- It’s easy to use and reduces the amount of code we have to write.