Search code examples
sveltesveltekit

Redirecting and returning data in SvelteKit form actions


You can send data after form submission by including it in the form action return. This data is accessed through the $page.form store.

If you want to redirect to a different page on form submission, you redirect to a different page by throwing a Redirect object. The redirect method only has two parameters (code and location), with no options to return data (unlike fail for example).

Is there any way to return data and redirect on form submission, besides just adding it all as URL parameters?

Thanks.


Solution

  • This is not possible. It would not work reliably, as redirecting while also keeping page state cannot be done without JavaScript. The application may also have to perform a reload after it has been updated which would interrupt this.