๐จ๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ๐ถ๐ป๐ด ๐ฅ๐ฒ๐ฎ๐ฐ๐ ๐ฅ๐ผ๐๐๐ฒ๐ฟ
Modern web apps need multiple pages. You need Home, About, and Contact pages. React Router lets you move between these pages without reloading the browser.
This library turns your React app into a Single Page Application (SPA). It makes your app feel fast and smooth.
Benefits of React Router:
- Faster navigation
- No page reloads
- Simple route management
- Dynamic routing support
How to start:
Install the library via npm: npm install react-router-dom
Wrap your app with BrowserRouter in your main entry file: import { BrowserRouter } from "react-router-dom";
ReactDOM.createRoot(document.getElementById("root")).render(
- Define your routes in App.jsx: import { Routes, Route } from "react-router-dom";
function App() {
return (
- Use the Link component to move between pages:
Standard HTML anchor tags reload the whole page. The Link component stops this. This keeps your app fast.
Pro tip: Do not add your Navbar to every single page. This creates duplicate code. Put your Navbar once inside App.jsx. This makes your code easier to maintain and keeps your structure clean.
React Router is essential for building:
- Portfolios
- Dashboards
- E-commerce sites
It helps you build professional projects with a smooth user experience.
Source: https://dev.to/aj_arul/understanding-react-router-building-multi-page-applications-in-react-14in