In this episode, we dive deeper into how Inertia handles navigation using links, and how this ties back to partial reloads and preserving scroll position on navigation. First, we look at how you can use link components just like router visits or form submissions—they all fetch new data and swap out components, the Inertia way.
We then experiment with some of the options you can pass to these links. For example, we show how you could use the preserve-scroll
prop to keep your scroll position when navigating to a new page (even though it's a bit of a contrived example for a profile page, but hey, sometimes demo code is like that!).
Next, we take a UI element—a "refresh comments" button—and temporarily turn it into a link to demonstrate that you can use the same link options (like partial reloads and preserve-scroll
) here too. Along the way, we show how partial reloads work: you can request to only reload specific props (like just the posts), making your navigation more efficient.
We wrap up by cleaning up the demo and switching things back, but leave the example code in case you want to reference how to use these features. The main takeaway: you can use all those handy Inertia navigation options with links, just like with manual visits and forms, giving you full control over how your app fetches and displays data as users interact.