Unverified Commit a58a869f authored by Shu Ding's avatar Shu Ding Committed by GitHub

(docs) Add example of redirection in Server Actions (#53485)

Based on the feedback from #53435, this PR adds an example of redirection inside Server Actions to the docs. Currently, we have examples of getting/setting cookies but there's nothing for `redirect()`.
parent 480e3a39
...@@ -548,6 +548,22 @@ async function create(data) { ...@@ -548,6 +548,22 @@ async function create(data) {
} }
``` ```
### Redirection
You can also trigger a redirection within a Server Action by using the `redirect` function.
```js highlight={8}
import { redirect } from 'next/navigation'
async function addItem(data) {
'use server'
await saveToDb({ data })
redirect('/success')
}
```
## Glossary ## Glossary
### Actions ### Actions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment