Performance: Single Page Application concept
This concept affects initial page load speed and interaction responsiveness by loading content dynamically without full page reloads.
import { useNavigate } from 'react-router-dom'; function LoadPage() { const navigate = useNavigate(); navigate('/about'); } // Or inside a component: // const navigate = useNavigate(); // navigate('/about');
function loadPage() { window.location.href = '/about'; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full page reload on navigation | High (reloads entire DOM) | Multiple (full reflow) | High (full repaint) | [X] Bad |
| Client-side routing with React Router | Low (updates part of DOM) | Single or none | Low (partial repaint) | [OK] Good |
| Loading entire app bundle upfront | N/A | N/A | Blocks rendering during JS parse | [X] Bad |
| Code splitting with lazy loading | N/A | N/A | Non-blocking JS load | [OK] Good |
import { BrowserRouter, Routes, Route } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<Routes>
<Route path='/' element=<Home /> />
<Route path='/about' element=<About /> />
</Routes>
</BrowserRouter>
);
}/about URL?Route with path '/about' renders the About component inside BrowserRouter.import { BrowserRouter, Routes, Route } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<Routes>
<Route path='/' component={Home} />
<Route path='/profile' element=<Profile /> />
</Routes>
</BrowserRouter>
);
}Pass the test and this pattern moves unknown