๐จ๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ๐ถ๐ป๐ด ๐ฅ๐ฒ๐ฎ๐ฐ๐ ๐ฅ๐ผ๐๐๐ฒ๐ฟ
Modern web apps need multiple pages like Home, About, and Contact. You want these pages to load without refreshing the browser. React Router solves this problem.
It lets you build Single Page Applications (SPA). This makes your app feel fast and smooth.
Benefits of React Router:
- Faster navigation
- No page reloads
- Better user experience
- Easy route management
- Dynamic routing support
How to set it up:
Install the library: npm install react-router-dom
Wrap your app in 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:
The Link component stops the browser from a full reload. This is better than using standard anchor tags.
Pro tip: Do not add your Navbar to every page. Place it once inside App.jsx. This prevents duplicate code and makes maintenance easy.
You can use this for portfolio sites to organize sections like:
- Skills
- Projects
- Experience
- Contact
React Router is a tool you need for professional projects like dashboards or e-commerce sites. It simplifies your workflow and improves performance.
Source: https://dev.to/aj_arul/understanding-react-router-building-multi-page-applications-in-react-14in