Router Setup

Install and Wrap the App

React Router maps URLs to components, so an SPA can have real URLs (/about, /users/7) without page reloads.

Example

Install it:

npm install react-router-dom
// main.jsx
import { createRoot } from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import App from './App';

createRoot(document.getElementById('root')).render(
  <BrowserRouter>
    <App />
  </BrowserRouter>
);