#Can't see URL params in the action (but loader is fine)

1 messages · Page 1 of 1 (latest)

formal topaz
#

I'm trying to access the URL params in the action function but unfortunately they are null. It looks like they are wiped when the form for the route is submitted. It works in the loader function no problem using:

const url = new URL(request.url)
const userHash = url.searchParams.get("id")
const userId = url.searchParams.get("ref")

Is there a simple way to access them in the action function. (I presume I don't have to pass data from the loader to the action via form hidden fields?

cursive plaza
#

The submit of a form is a separate request, and there is no automation in adding url params from the currrent route. I think the most "remix" way is to add them as hidden input fields like you mention. Or you can add them in a custom onSubmit or set them in the action property of the form.

formal topaz
#

Thanks, hmm that feels a bit weird to use hidden fields but maybe thats just a case of getting used to it. Out of interest how would you set them on the action property of the form. I dont think ive seen that. Thanks for your help btw.

graceful coral
#

you can use ExistingSearchParams from Remix Utils to add all search params to a form

#

it's just one component and it adds one hidden input per search param in the current URL

cursive plaza