跳到内容

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