Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Next.js 16+ · Type Alias

RedirectType

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.

How it works

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.

Syntax

redirect(path, type)

Parameters

NameTypeDescription
pathstringThe destination URL passed to redirect; it may be relative or absolute.
typeRedirectTypeThe history operation to perform: RedirectType.replace or RedirectType.push.

Returns

No value; redirect transfers control to the framework's redirect handling.

Key points

  • RedirectType groups the permitted redirect-history choices for redirect's second argument.
  • Use RedirectType.replace when the destination should replace the current browser-history entry.
  • Use RedirectType.push when the destination should create a new browser-history entry.
  • The default is push in Server Actions, so an explicit RedirectType is useful when documenting or enforcing intent.
  • Outside Server Actions, redirect defaults to replace unless the applicable context supports an override.

Common mistakes

  • Passing replace or push to redirect in a Server Component does not change the resulting history behavior.

Example: Choose the browser history behavior

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.

When to use it

Replace after a mutation

A successful Server Action should navigate without leaving the submitted form as the previous history entry.

Push a destination onto history

A navigation should let the user return to the previous page with the browser Back button.

Interview questions

QWhat is RedirectType used for?

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.

QHow do you use RedirectType with redirect?

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.

QDoes RedirectType affect every redirect context?

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.

  • redirect
  • next/navigation
  • Server Actions
  • Server Components

Source: redirect - Next.js. Checked 2026-10-15.