Introducing React Router
React Router started out as a simple, declarative routing library. It provides features to define and manage different routes for our app, as well as navigating between them. Recently, React Router can also be used as a React framework, providing ways to handle layouts and advanced server-side rendering. However, since this book focuses on Hooks, we will focus on React Router as a library.
The library consists of three main components:
- The
BrowserRouter
component, which provides a context to use routing in - The
Routes
component, which lets us define some routes and renders the component of the currently active route - The
Route
component, which lets us define a specific route and component to render
Additionally, the library provides components to create links to certain routes (using the Link
and NavLink
components), as well as Hooks to get parameters from the URL (Param Hook) and to navigate (Navigation Hook).
Now, let...