permanentRedirect()

Performs a permanent (308) redirect to a new URL.

Since Next 14 Spec ↗

Syntax

import { permanentRedirect } from 'next/navigation'; permanentRedirect(path, type?)

Parameters

NameTypeRequiredDescription
path string Yes The destination URL.
type 'replace' | 'push' No History behavior in Server Actions (default `replace`).

Returns

never — Throws to halt rendering and issue a 308 redirect.

Examples

import { permanentRedirect } from 'next/navigation'

export default async function Page({ params }) {
  const { slug } = await params
  const user = await db.users.findBySlug(slug)
  if (user?.renamedTo) {
    permanentRedirect(`/u/${user.renamedTo}`)
  }
  return <Profile user={user} />
}
'use server'
import { permanentRedirect } from 'next/navigation'

export async function migrate() {
  permanentRedirect('/new-home')
}

Notes

Like `redirect()` but emits HTTP 308 (Permanent Redirect / 303 in Server Actions when appropriate), signaling search engines to update links. It throws control-flow, so keep it outside try/catch. Use for permanent moves; use `redirect()` for temporary ones.

See also