#Preserve search params over route change

1 messages · Page 1 of 1 (latest)

trail fjord
#

I've got a form spread out over multiple pages (there are actions/fetches needed dynamically at each step) and I decided to store the state in the URL.

There's only 5 or 6 variables, so i'm storing them in hidden fields and passing them to the actions with the form, and pulling them from the request on the loaders. But this feels hacky, as I have to track them over 5 pages.

What's the best way to preserve it between transitions? I know I could store it in session storage, but I like how the url enables sharing. I also can't persist it to a DB until the final step submission

wispy shoal
#

the only way to keep them in the URL across navigations is to add them to the new URL the user goes to after the navigation, so add them to each link/form

trail fjord
#

Ok, thanks. I'm on the right path so. Do you think it's smarter to pull them in the loader & pass them down or use useSearchParams from the client, for the links at least?

azure arch
wispy shoal
#

let's say the user is on /a?param=1 and clicks a link to /b, the question is how to automatically send the user to /b?param=1

azure arch
#

Ah, ok. I was looking at the form spread out over multiple pages and thought there might be some overlap

#

Gotcha. I wonder if there’s a way to encapsulate the behavior of appending existing params into a link component. Like ParamsPassAlongLink

#

Maybe w/ an optional prop for limiting it to just those params listed in the prop’s value, defaulted to all props get passed