Contents of React Interview Questions

Comprehensive collection of React interview questions and answers covering hooks, components, state management, and best practices.

What are the differences between BrowserRouter and HashRouter?

Both BrowserRouter and HashRouter are types of Routers provided by React Router, but they differ mainly in how they manage URLs.

FeatureBrowserRouterHashRouter
URL StructureClean URLs (/about)URLs with hash (/#/about)
History ManagementUses HTML5 history APIUses URL hash for storing routes
Server ConfigurationNeeds server-side setup (e.g., fallback to index.html)No server setup required
Use CaseModern web apps with server supportStatic file servers, GitHub Pages
SEO FriendlinessBetter SEO (search engines can index clean URLs)Not ideal for SEO

Example:

  • BrowserRouter: https://example.com/about
  • HashRouter: https://example.com/#/about

Summary: Use BrowserRouter if your server is configured properly; use HashRouter when you don’t control the server (like GitHub Pages).