React / Next.js

React Router

BrowserRouter, Routes, Route, Link, useNavigate, useParams, nested routes, protected routes

20 interview questionsยท
Junior
1

What is BrowserRouter in React Router?

Answer

BrowserRouter uses the browser's History API to create clean URLs without hash. Unlike HashRouter which adds a # in the URL, BrowserRouter provides a better user experience and SEO. However, it requires server configuration to properly handle routes in production.

2

Which component should be used to define a route in React Router?

Answer

The Route component defines a match between a URL path and a component to display. It must be placed inside a Routes component to work correctly. Each Route specifies a path and an element to render when the URL matches.

3

What is the purpose of the Link component in React Router?

Answer

Link creates navigation links without reloading the page. Unlike the native HTML <a> tag, Link intercepts clicks and uses the History API to change the URL. This preserves application state and provides faster, smoother navigation.

4

What is the role of the Routes component?

5

How to retrieve a URL parameter like :id in /user/:id?

+17 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free