跳到内容

forbidden.js

此功能目前为实验性功能,可能会发生变化,不建议用于生产环境。请试用并分享您在 GitHub 上的反馈。

当在身份验证期间调用 forbidden 函数时,forbidden 文件用于渲染 UI。除了允许您自定义 UI 外,Next.js 还会返回 403 状态码。

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>
  )
}

参考

Props

forbidden.js 组件不接受任何 props。

版本历史

版本变更
v15.1.0引入 forbidden.js