DEV Community

Aman Kureshi
Aman Kureshi

Posted on

React Router Basics β€” Navigating Your React App the Right Way 🧭

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)