Skip to main content
InterviewHubPRO
Section Overview
Q80

Question 80 of 407

Part 2: React Router & Navigation (78 - 88)

20%
React Core & Hooks (407 Qs)•Part 2: React Router & Navigation (78 - 88)

What are the <Router> components of React Router v6?

junior LevelCode ExampleComponentsRouting

React Router v6 provides below 4 <Router> components:

  1. <BrowserRouter>:Uses the HTML5 history API for standard web apps.
  2. <HashRouter>:Uses hash-based routing for static servers.
  3. <MemoryRouter>:Uses in-memory routing for testing and non-browser environments.
  4. <StaticRouter>:Provides static routing for server-side rendering (SSR).

The above components will create browser, hash, memory and static history instances. React Router v6 makes the properties and methods of the history instance associated with your router available through the context in the router object.

Practical Code Example

jsx
// React Router v6 core router components:
// 1. <BrowserRouter> (HTML5 History API)
// 2. <HashRouter> (URL Hash /#/)
// 3. <MemoryRouter> (In-memory navigation for tests / React Native)
import { BrowserRouter, Routes, Route } from 'react-router-dom';