In this episode, we dig into the behavior that happens when users submit the search form, not just type into it. Originally, our search was "instant search" style, updating results as the user typed. But what about when someone presses Enter after typing in a query?
We start by adding handling for the form's onSubmit
event, log out when a search is submitted, and inspect the available state to grab the current search query. Then, we experiment with refreshing the page and adding the search query to the URL's query string, which means if someone refreshes or leaves and comes back, their search is preserved.
After that, we introduce using navigation APIs to send users to new URLs when they submit, like a dedicated search page, not just staying in place. This lets you build a more traditional search result page—handy if you want separate, indexable search result pages (good for SEO), or if you want a search page experience more similar to popular sites.
We also touch on how you might adapt this whether you're using classic navigation, frameworks like Inertia, or your own flavor—basically, you get to pick if you want to update the search results instantly, redirect to a new page, or both. The choice is yours, and now you know how to hook into the form submission to do it!