3 ms·
Would love to hear your thoughts as well on this! Especially with regards to remembering scroll position between route navigations in an infinite scroll compone
by 2Pacalypse- 8y ago
Would love to hear your thoughts as well on this! Especially with regards to remembering scroll position between route navigations in an infinite scroll component that fetches its content asynchronously.
- djKianoosh 8y agoi've thought about this some.. seems to me the url/hash route needs to tell us both the app state and UI state, but most routers dont do this
- joshtynjala 8y agoYou can save arbitrary data when you push a new state with the HTML history API. This data is restored when you go back, and it does not affect the URL. Both React Router and Reach Router allow you to programmatically navigate and use this capability. I've used it on multiple occasions to restore both app state and UI state when navigating back. It's a little more work, of course. You can't just link to a simple URL. You need an event listener that creates the state object and tells the router to navigate manually. You may also need to ensure that any back buttons in your UI actually go back into the history instead of adding a new entry. It would be nice if it were easier, but once you get it working, the level of polish compared to most web apps makes it feel worth the effort.