Skip to main content
The redirect function lets you redirect the user to another URL. It can be used in Server Components, Route Handlers, and Server Functions.

redirect()

Issues a 307 Temporary Redirect (or a meta redirect when used inside a streaming context). In Server Actions it issues a 303 See Other.

Parameters

string
required
The URL to redirect to. Can be a relative or absolute path.
'replace' | 'push'
The redirect type. Defaults to 'push' in Server Actions and 'replace' everywhere else.
You can use the RedirectType enum for the type parameter:
The type parameter has no effect in Server Components.

Returns

redirect does not return a value. It throws a NEXT_REDIRECT error internally, so it does not need return redirect(...) — the TypeScript type is never.

permanentRedirect()

Identical to redirect but issues a 308 Permanent Redirect instead of 307.

Behavior

  • In Server Actions and Route Handlers, call redirect outside any try/catch block, since it works by throwing an error.
  • redirect can be called in Client Components during rendering, but not inside event handlers. Use useRouter for event-driven navigation.
  • redirect accepts absolute URLs for external redirects.
  • To redirect before rendering, use redirects in next.config.js.

Why 307 and 308?

Traditional 302 and 301 redirects caused browsers to downgrade POST requests to GET. Using 307 (temporary) and 308 (permanent) preserves the original HTTP method.

Examples

Server Component

app/team/[id]/page.tsx

Client Component (during render)

components/client-redirect.tsx
When used in a Client Component during initial SSR, this performs a server-side redirect.

Via a Server Action

app/actions.ts
app/client-form.tsx

Version history