Description
Problem
There is no way to use replaceState with use:enhance.
Solution
Add an option to enhance API to use replaceState instead pushState if needed.
const { form, enhance, reset } = superForm(data.form, {
applyAction: true,
invalidateAll: true | 'force',
resetForm: true,
replaceState: true
});
Context
I'm working on a PWA that behaves very similarly to a native app, so I need to handle navigation taking into account that the user will use gestures like going back, which triggers the browser's back action.
Let's assume a scenario in which a user navigates to the following route.
Main View > List View > Create Form
When the user submits the form, the action that handles it returns a redirect to List View
, so the current route would be as follows:
Main View > List View
At this point, if the user presses back, their intention is to go to Main View
, but the browser will redirect them to the Create Form
view again. To handle this situation, the solution with SvelteKit enhance is to use use:enhance={{replaceState: true}}
but I can't find a way to handle it with the SuperForms implementation.
I think other users who are doing something similar might need it too.
PD: Thanks for this excellent lib. Loves what you are doing here !