Performance: Client-side routing concept
MEDIUM IMPACT
Client-side routing affects page load speed by reducing full page reloads and improves interaction responsiveness by updating only parts of the page.
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom'; function App() { return ( <BrowserRouter> <nav> <Link to='/about'>About</Link> <Link to='/contact'>Contact</Link> </nav> <Routes> <Route path='/about' element={<About />} /> <Route path='/contact' element={<Contact />} /> </Routes> </BrowserRouter> ); }
function App() { return ( <div> <button onClick={() => window.location.href = '/about'}>About</button> <button onClick={() => window.location.href = '/contact'}>Contact</button> </div> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full page reload navigation | High (reloads entire DOM) | Multiple (full page) | High (full repaint) | [X] Bad |
| Client-side routing with react-router | Low (updates partial DOM) | Single or few | Low (partial repaint) | [OK] Good |