如果事情真的出错了 - 在加载根布局数据时发生错误,或者在渲染错误页面时发生错误 - 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>