This feature is currently experimental and subject to change, it’s not recommended for production. Try it out and share your feedback on GitHub.

forbidden.js

The forbidden file renders UI when the forbidden function is invoked.

Before streaming starts, Next.js returns a 403 status code. After streaming starts, the status code remains 200 and the forbidden UI renders in the response. Next.js injects a <meta name="robots" content="noindex" /> tag in both cases. See Status codes for details.

app/forbidden.tsx
import Link from 'next/link'

export default function Forbidden() {
  return (
    <div>
      <h2>Forbidden</h2>
      <p>You are not authorized to access this resource.</p>
      <Link href="/">Return Home</Link>
    </div>
  )
}

Reference

Props

forbidden.js components do not accept any props.

Good to know

Next.js sends each forbidden.js file with every route under its segment, even when forbidden() is never called, and loads the Client Components it imports on those pages. Prefer Server Components and <Link> there over interactive UI.

Version History

VersionChanges
v15.1.0forbidden.js introduced.

Last updated