Replace after a mutation
A successful Server Action should navigate without leaving the submitted form as the previous history entry.
Next.js 16+ · Type Alias
RedirectType selects whether redirect replaces the current browser-history entry or pushes a new one. It is imported from next/navigation and supplied as redirect's second argument.
RedirectType provides the two choices accepted by redirect: replace the current browser-history entry or push a new entry. Import it from next/navigation and pass the selected member as redirect's second argument; that argument does not affect behavior in Server Components.
redirect(path, type)| Name | Type | Description |
|---|---|---|
path | string | The destination URL passed to redirect; it may be relative or absolute. |
type | RedirectType | The history operation to perform: RedirectType.replace or RedirectType.push. |
No value; redirect transfers control to the framework's redirect handling.
import { redirect, RedirectType } from 'next/navigation'
export async function saveAndContinue() {
// Save data here
redirect('/dashboard', RedirectType.replace)
}This Server Function redirects to the dashboard while explicitly replacing the current history entry.
A successful Server Action should navigate without leaving the submitted form as the previous history entry.
A navigation should let the user return to the previous page with the browser Back button.
RedirectType is the set of options for redirect's type argument. RedirectType.replace replaces the current browser-history entry, while RedirectType.push adds a new entry.
Follow-up: Which default should be expected? In Server Actions, redirect defaults to push; in other contexts, it defaults to replace.
Import RedirectType from next/navigation and pass RedirectType.replace or RedirectType.push as redirect's second argument. The path remains the first argument.
Follow-up: What happens if the second argument is omitted? redirect selects push in Server Actions and replace elsewhere.
The type argument controls browser history where that behavior applies, but it has no effect in Server Components. Therefore, choosing replace versus push there does not alter the result.
Follow-up: What else should be remembered about redirect? It does not return a value; it transfers control through Next.js redirect handling.
redirectnext/navigationServer ActionsServer Components