3 ms·
Never thought about scroll position (tho SPA I’ve built recently I think does it ok). How do you solve it?
by dzhiurgis 1y ago
Never thought about scroll position (tho SPA I’ve built recently I think does it ok). How do you solve it?
- throwawaylaptop 1y agoI'm a self taught PHP/jQuery/bootstrap guy with a small saas. I handle page scroll position by literally saving it into some session data cookie and when you go back I check where your scroll was and I fix it for you. I'm not a genius or skilled... But I cared so I did it.
- PaulHoule 1y agoI’ve done it like that. It’s not a lot of code.
- cyco130 1y agoI write some of my thoughts on this sone years ago. The library described at the end is now fairly out of date but the ideas and suggestions are still good, I think. https://dev.to/cyco130/how-to-get-client-side-navigation-right-2adh https://dev.to/cyco130/how-to-get-client-side-navigation-rig...
- fleebee 1y agoDepends on what you're using for routing. In Tanstack Router it's a boolean you set when creating the router. The documentation nicely lays out what's being done under the hood, and it's quite a bit.[1] I wouldn't try that at home. In React Router you just chuck a <ScrollRestoration /> somewhere in your DOM.[2] [1]: https://tanstack.com/router/v1/docs/framework/react/guide/scroll-restoration#scroll-restoration https://tanstack.com/router/v1/docs/framework/react/guide/sc... [2]: https://reactrouter.com/6.30.1/components/scroll-restoration https://reactrouter.com/6.30.1/components/scroll-restoration