Skip to main content
基本 Svelte
介绍
反应性
属性
逻辑
事件
绑定
类和样式
动作
转换
高级 Svelte
高级反应性
重用内容
运动
高级绑定
高级转换
上下文 API
特殊元素
<script module>
后续步骤
基本 SvelteKit
介绍
路由
加载数据
标题和 cookie
共享模块
表单
API 路由
$app/state
错误和重定向
高级 SvelteKit
钩子
页面选项
链接选项
高级路由
高级加载
环境变量
结论

如果事情真的出错了 - 在加载根布局数据时发生错误,或者在渲染错误页面时发生错误 - SvelteKit 将返回到静态错误页面。

¥If things go really wrong — an error occurs while loading the root layout data, or while rendering the error page — SvelteKit will fall back to a static error page.

添加一个新的 src/routes/+layout.server.js 文件以查看实际效果:

¥Add a new src/routes/+layout.server.js file to see this in action:

src/routes/+layout.server
export function load() {
	throw new Error('yikes');
}

你可以自定义后备错误页面。创建 src/error.html 文件:

¥You can customise the fallback error page. Create a src/error.html file:

src/error
<h1>Game over</h1>
<p>Code %sveltekit.status%</p>
<p>%sveltekit.error.message%</p>

此文件可以包含以下内容:

¥This file can include the following:

  • %sveltekit.status% — HTTP 状态代码

    ¥%sveltekit.status% — the HTTP status code

  • %sveltekit.error.message% — 错误消息

    ¥%sveltekit.error.message% — the error message

上一页 下一页
1
2
<h1>home</h1>