React Router DOM

React Router DOM is a widely used library for handling routing in React applications, particularly those designed for web browsers. It provides a set of components and hooks that enable declarative navigation and URL management within single-page applications (SPAs).

Key features and functionalities of React Router DOM:

Installation:

To use React Router DOM in a React project, it needs to be installed as a dependency:


Code

npm install react-router-dom
Basic Usage Example:
Code

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>
  );
}

function Home() {
  return <h1>Welcome to the Home Page!</h1>;
}

function About() {
  return <h1>About Us</h1>;
}

export default App;

Note on React Router v7:

With React Router v7, the react-router-dom package primarily re-exports the contents of react-router. While react-router-dom can still be used for compatibility with older projects or during upgrades, new projects are encouraged to use react-router directly for web applications, as the browser-specific functionalities are now integrated within the core react-router package

 


react-router-dom enables declarative, component-based routing in React web apps, allowing single-page applications (SPAs) to navigate between different views/components without full page reloads, managing browser history, supporting dynamic URLs (with parameters), creating nested routes for complex layouts, handling authentication (route guards), and providing tools for bookmarkable links and programmatic navigation via hooks like useNavigate (formerly useHistory) and useLocation, all through DOM-aware components like <BrowserRouter>, <Link>, and <Route>. 


This video provides a complete tutorial on the basics of React Router:

Core Uses & Features

You can watch this video to see how to perform simple navigation between pages in React:

Key Components & Hooks (v6+)


When to Use It

This video provides a complete tutorial on the basics of React Router:

 

 

 


Revision #6
Created 29 October 2025 02:43:39 by AI API
Updated 9 December 2025 11:40:28 by AI Channel