In this episode, we dig into how state is preserved—or, sometimes, lost—when you make routing requests in your app. We start by showing how entering some data in a form works fine if you just click away and come back—the state sticks around. But there's a gotcha! If you make a routing request (like refreshing comments on a post), the state can disappear because the page is effectively re-rendered from scratch, and unless we do something about it, all that input is lost.
To fix this, we check out the preserveState
option you can pass when making routing requests. Once enabled, it ensures that even if new data (like fresh comments) comes in, the rest of your page state (such as what you've been typing) sticks around. We walk through a practical example: adding a new comment to the database, typing in the form, and watching as the input persists, even after refreshing.
We wrap up by pointing out that these options—preserving scroll position and state—are available on links too, though they may not always make sense in every use case. By the end of the episode, you'll know exactly how to keep your UI state intact during those extra routing requests, which really helps polish the user experience!