Consider a SvelteKit app with multiple pages. What is the main behavior when you click a link to go from one page to another?
Think about how modern apps avoid full page reloads to feel faster.
SvelteKit uses client-side routing to update only the parts of the page that change, making navigation smooth and fast without full reloads.
In a SvelteKit project, which file path correctly defines a page route for the URL /about?
Routes are defined inside the src/routes folder with +page.svelte files for pages.
SvelteKit uses the src/routes folder where +page.svelte files correspond to routes. So src/routes/about/+page.svelte defines the /about page.
load function called in SvelteKit?In SvelteKit, the load function can be exported from a page or layout. When does this function run?
Think about when data needs to be fetched for each page visit.
The load function runs on the server during initial page load and on the client during client-side navigation to fetch data needed for the page or layout.
Given this +page.server.js file in SvelteKit:
export async function load() {
const res = await fetch('/api/data');
const data = await res.json();
return { data };
}The page shows an error: fetch is not defined. Why?
Remember that server-side code may not have browser APIs like fetch globally.
In SvelteKit, server-side load functions receive a fetch function as an argument to make requests. The global fetch is not available by default on the server.
Which statement best describes how SvelteKit combines server-side rendering and client-side hydration?
Think about how modern frameworks deliver fast initial loads and interactivity.
SvelteKit pre-renders pages on the server to HTML for fast loading and SEO, then the client-side Svelte code hydrates the HTML to add interactivity.