React Router is the standard routing library for React apps. It lets you build multi-page experiences using components.
π¦ Why use React Router?
β’ Handle different URLs without reloading the page
β’ Create a single-page app (SPA) with multiple views
β’ Dynamically render components based on route
π§± Basic setup:
1.Install:
npm install react-router-dom
2.Setup routing:
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Home from "./Home";
import About from "./About";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
);
}
3.Navigation:
import { Link } from "react-router-dom";
Home
About
π Key Components:
β’ β Wraps your app
β’ β Defines all the routes
β’ β Matches the path and shows the component
β’ β For internal navigation (no page reload)
React Router makes navigation in React smooth, dynamic, and fast β a must-learn for real-world apps!
Top comments (0)