Performance: Client-side routing concept
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 |
/about?
import { BrowserRouter, Routes, Route } from 'react-router-dom';
function App() {
return (
Home} />
About Us} />
Contact} />
);
}import { BrowserRouter, Routes, Route } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<Route path='/' element={} />
<Routes>
<Route path='/about' element={} />
</Routes>
</BrowserRouter>
);
}Pass the test and this pattern moves unknown