InterviewHubPRO
Section Overview
Q79

Question 79 of 445

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

18%
React & Modern Frontend (445 Qs)•Part 2: React Router & Navigation (78 - 88)

How React Router is different from history library?

React Router is a wrapper around the history library which handles interaction with the browser's window.history with its browser and hash histories. It also provides memory history which is useful for environments that don't have global history, such as mobile app development (React Native) and unit testing with Node.

Practical Code Example

jsx
// 'history' is a low-level library managing browser history stack.
// 'React Router' wraps history and provides declarative components (<Routes>, <Route>, <Link>):
import { useNavigate } from 'react-router-dom';

function LogoutButton() {
  const navigate = useNavigate();
  return <button onClick={() => navigate('/login')}>Logout</button>;
}