【发布时间】:2021-11-18 03:32:23
【问题描述】:
基本上,如何做ff。在 SvelteKit 中:
- 先添加自定义 404 页面。
- 有一个不同的通用错误页面,该页面将显示有关 SvelteKit 中错误的消息/描述
【问题讨论】:
基本上,如何做ff。在 SvelteKit 中:
【问题讨论】:
通读docs后,我找到了答案,并在下面创建了更具体的步骤来实现我喜欢的:
__error.svelte。<script context="module"> export function load({ error, status }) { return { props: { title: `${status}: ${error.message}` } }; } </script> <script> export let title; </script> <h1>{title}</h1>
load函数里面配置props):<script context="module"> export function load({ error, status }) { return { props: { message: error.message, status // same as status: status } }; } </script> <script> import ErrorScreen from '../components/screens/ErrorScreen.svelte'; // your own Error screen component import NotFoundScreen from '../components/screens/NotFoundScreen.svelte'; // your own 404 screen component export let message; export let status; </script> {#if status == 404} <!-- Used '==' instead of '===' to match string/number status code (just to be sure) --> <NotFoundScreen /> {:else} <ErrorScreen {message} {status} /> {/if}
#if status == 404 更改为喜欢#if status == 500 来测试它,看看是否一切正常。 (别忘了改回404)。【讨论】: