Next.js Discord

Discord Forum

Replace state before redirect for multi-step form

Unanswered
Australian Freshwater Crocodile posted this in #help-forum
Open in Discord
Australian Freshwater CrocodileOP
Hi all! šŸ‘‹šŸ½ I have a multi-step form where the first step e.g. /create creates the resource and the server action redirects the user to the second step to keep editing, e.g. /:id/edit/2

I would love if i were able to replace the state right before redirection, so let's say the creation succeeds in the Server Action then the history state is replaced to /:id/edit/1 and then the user is redirected (push state) to /:id/edit/2.

Can you think of a way to do this? Without moving all redirection logic to client, if possible.

1 Reply

Australian Freshwater CrocodileOP
Maybe there's a general way of catching redirects and doing something before? But i'd need something from the Server Action, so i guess i can't do what i'm thinking of šŸ¤”