react-router-dom
Declarative, component-based routing for React web applications.
Fit
Bundle (gzip)
61.3 kB
194.2 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Single-page React apps need to map URLs to views, handle nested layouts, navigation, and route parameters, and keep the UI in sync with the browser history — all of which is painful to build from scratch.
What It Does
react-router-dom provides routers, <Route> definitions, nested routes, data loaders, and navigation hooks like useNavigate and useParams. It is the standard routing solution for React on the web.
Installation
npm install react-router-domUsage Example
import { createBrowserRouter, RouterProvider, Link } from "react-router-dom";
const router = createBrowserRouter([
{ path: "/", element: <Link to="/about">About</Link> },
{ path: "/about", element: <h1>About us</h1> },
]);
export default function App() {
return <RouterProvider router={router} />;
}Related packages
Fast, composable command palette for React — keyboard-driven search UI with fuzzy filtering and accessible markup out of the box.
@dnd-kit/coreReactModern, accessible drag-and-drop toolkit for React — fully customizable with keyboard support, collision detection, and zero dependencies.
embla-carousel-reactReactLightweight, extensible carousel library for React — smooth scrolling, touch/mouse drag, and full CSS control without prescribing markup.
flagsReactProvider-agnostic feature flags SDK for Next.js and React — toggle features without redeploying.
framer-motionReactProduction-ready declarative animation library for React — gestures, layout animations, and scroll-driven effects with a clean API.