In traditional server-rendered websites, when a user scrolls halfway down a long catalog page, clicks a link to view a product, and then clicks the browser "Back" button:
The browser automatically restores the exact scroll position where they left off.
In a naive Single-Page Application:
Clicking a link navigates to a new view, but the viewport remains scrolled down at the previous position!
Clicking "Back" sends the user to the top of the catalog page, forcing them to search and scroll all over again!
This jarring UX flaw is solved in modern React Router via Scroll Restoration.
18{/* Automatically restores scroll position on navigation! */}
19<ScrollRestoration/>
20</div>
21);
22}
Custom Scroll Keys (Tabs and Query Params)
By default, scroll positions are keyed by the URL pathname. If you have tabs that change query params (?tab=reviews) and want to preserve scroll independently:
1<ScrollRestoration
2getKey={(location, matches)=>{
3// Return key string to match against
4return location.pathname + location.search;
5}}
6/>
3. Optimistic Route Transitions with useNavigation
When users click a link that loads data via a loader, there may be a 150–300ms delay while data fetches across the network.
Without visual feedback, the user wonders: "Did my click register?"
React Router provides the useNavigation() hook to inspect active in-flight transitions: