forbidden.jsExperimental
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>
)
}app/forbidden.jsx
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.jsfile with every route under its segment, even whenforbidden()is never called, and loads the Client Components it imports on those pages. Prefer Server Components and<Link>there over interactive UI.
Version History
| Version | Changes |
|---|---|
v15.1.0 | forbidden.js introduced. |