Svelte and SvelteKit 5 · SvelteKit
Load data on the server
A +page.server.ts load function runs on the server, and its result is passed to the page as data.
// +page.server.ts
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ params, fetch }) => {
const res = await fetch(`/api/posts/${params.slug}`);
return { post: await res.json() };
};
Official Svelte and SvelteKit 5 documentation