What are the components of the React Router?

The major Components of the React Router are:

  • BrowserRouter: BrowserRouter is actually a router implementation which uses the HTML5 history API i.e., pushState, replaceState and the popstate event in order to keep the UI in sync with the URL. It is the parent component which is used to store all of the other components.
  • Route: Route is basically the conditionally shown component which renders some UI when its path matches the current URL.
  • Link: The Link component is used to create links to different routes and implement navigation around the application and it works like HTML anchor tag
  • Switch: The Switch component is used to render only the first route that matches the location rather than rendering all the matching routes. Although there is no defying functionality of SWITCH tag in our example application as none of the LINK paths are ever going to coincide. But let’s say we have a route, then all the Route tags are going to be processed which start with ‘/’. This is when we need SWITCH statement to process only one of the statements.