Next.js Discord

Discord Forum

Server Action navigation

Answered
House Wren posted this in #help-forum
Open in Discord
House WrenOP
How can you navigate from within a server action?

I know we have redirect available to us to redirect the user to another page, but what if we just wanted to navigate to a different page after the server action succeeds similar to how we navigate with <Link href={} />

My use case is a server-side rendered form posting to a server action that navigates to the next page when processed (DB updates records).

I've been using redirect to achieve the above, but I lose the browser's stack (back button doesn't go back to the previous page)

Thanks in advance!
Answered by fuma
This is a bug which is fixed in 13.4.20, see https://github.com/vercel/next.js/issues/53911
You can upgrade to the latest canary version of Next and try again.
View full answer

3 Replies

This is a bug which is fixed in 13.4.20, see https://github.com/vercel/next.js/issues/53911
You can upgrade to the latest canary version of Next and try again.
Answer
By default, it will push a new history entry rather than “replace”.
As a workaround, use client side navigation like router.push
House WrenOP
oh great, thank you!