react-router-dom is the DOM-specific package within the broader React Router project, distinct from react-router-native, which targets React Native mobile apps instead — it provides the components and hooks needed to build browser-based client-side routing: BrowserRouter to enable routing using the History API, Routes and Route to declare which component renders for which URL pattern, Link and NavLink for navigation, and hooks like useNavigate, useLocation, and useParams for programmatic access to routing state from within components.
1Understanding React Router DOM
react-router-dom is the DOM-specific package within the broader React Router project, distinct from react-router-native, which targets React Native mobile apps instead — it provides the components and hooks needed to build browser-based client-side routing: BrowserRouter to enable routing using the History API, Routes and Route to declare which component renders for which URL pattern, Link and NavLink for navigation, and hooks like useNavigate, useLocation, and useParams for programmatic access to routing state from within components.
Import routing pieces specifically from react-router-dom for web applications, not the base react-router package directly — react-router-dom re-exports everything from react-router plus the DOM-specific pieces like BrowserRouter, so importing from it alone is sufficient.
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<nav><Link to="/">Home</Link> | <Link to="/about">About</Link></nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
);
}2Practical Example
Here is a real-world application of React Router DOM showing how it is used in production React code.
import { useNavigate } from 'react-router-dom';
function LoginButton() {
const navigate = useNavigate();
const handleLogin = () => {
console.log('Logged in!');
navigate('/dashboard');
};
return <button onClick={handleLogin}>Log In</button>;
}3Best Practices
Follow these guidelines when working with React Router DOM:
1. Import routing components and hooks from react-router-dom for web apps, rather than react-router directly or react-router-native, which is for React Native
2. Keep react-router-dom's version consistent with your other React Router-related dependencies, since major versions have introduced meaningfully different APIs over time
3. Check the installed react-router-dom major version against documentation you're following, since v5's Switch/component-prop pattern differs meaningfully from v6's Routes/element-prop pattern
Tip: Import routing pieces specifically from react-router-dom for web applications, not the base react-router package directly — react-router-dom re-exports everything from react-router plus the DOM-specific pieces like BrowserRouter, so importing from it alone is sufficient.
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<nav><Link to="/">Home</Link> | <Link to="/about">About</Link></nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
);
}