用法
import { ExceptionPage } from './ExceptionPage.jsx'
// One variant per route: app/not-found.jsx, a 403 from the server, an error boundary, a failed load.
<ExceptionPage
locale="en"
variant="server-error" // 'not-found' | 'no-access' | 'server-error' | 'offline'
reference={error.digest}
onSearch={(words) => router.push('/search?q=' + encodeURIComponent(words))}
onAction={async (variant, which) => {
if (variant === 'server-error' && which === 'primary') return reset()
if (variant === 'offline' && which === 'primary') return await reload() // false keeps counting down
if (variant === 'not-found' && which === 'primary') router.push('/')
}}
/>属性
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | 内置文字的语言。 |
variant | 'not-found' | 'no-access' | 'server-error' | 'offline' | — | 显示哪一种。不传时上方出现分段控件,可在四种之间切换。 |
reference | string | — | 服务出错时显示的请求编号或错误编号,带复制按钮。 |
retryIn | number | 10 | 离线时自动重试的间隔秒数。 |
onAction | (variant, which: 'primary' | 'secondary' | 'link', link?) => Promise<boolean | void> | void | — | 点击操作时调用。返回 false 表示没有成功(离线时会继续倒计时重试)。 |
onSearch | (words: string) => void | — | 在“找不到”页提交搜索时调用。 |
labels | object | — | 替换任意内置文字(键名见 copy.js)。 |
装进你的项目
把指令粘贴给 Codex 或 Claude Code。Agent 会读取公开的源码,先告诉你要写入哪些文件,再把区块连同它用到的组件一起加进项目。
ExceptionPage.jsxexception-page.csscopy.jskit.jsxkit.cssui/base-button/ui/copy-button/ui/text-input/ui/segmented-control/tokens.cssREADME.md
区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。