Svelte Kit
Introduction
SvelteKit is a framework for rapidly developing robust, performant web applications using Svelte. If you're coming from React, SvelteKit is similar to Next.
Data Pre-rendering
SvelteKit allows server-side rendering, but also can be disabled to let application be single app application (spa)
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';
/** @type {import('./$types').PageLoad} */
export const load:PageLoad = ({ params }) => {
if (params.slug === 'hello-world') {
return {
title: 'Hello world!',
content: 'Welcome to our blog. Lorem ipsum dolor sit amet...'
};
}
throw error(404, 'Not found');
}
// Disable SSR
// export const csr = true;
// export const ssr = false;API
The page can act as an api
Hook
'Hooks' are app-wide functions you declare that SvelteKit will call in response to specific events, giving you fine-grained control over the framework's behaviour
Every time the SvelteKit server receives a request — whether that happens while the app is running, or during prerendering — and determines the response. It receives an
eventobject representing the request and a function calledresolve, which renders the route and generates aResponse. This allows you to modify response headers or bodies, or bypass SvelteKit entirely
Allows you to modify (or replace) a
fetchrequest that happens inside aloadoractionfunction that runs on the server
Last updated
Was this helpful?