Complete the code to export a load function in a Svelte layout.
export const [1] = async ({ params }) => { return { id: params.id }; };
The load function is the correct export name for loading data in a Svelte layout.
Complete the code to access route parameters inside the load function.
export const load = async ({ [1] }) => {
return { slug: params.slug };
};The params object contains route parameters like slug.
Fix the error in the load function to correctly return data.
export const load = async () => {
[1] { user: 'Alice' };
};return keyword.The load function must return an object containing the data.
Fill both blanks to create a load function that fetches JSON data and returns it as props.
export const load = async ({ [1] }) => {
const response = await fetch('/api/data');
const data = await response.[2]();
return { data };
};params instead of fetch in the first blank.text() instead of json() to parse response.The first blank is fetch to use SvelteKit's enhanced fetch function, and the second blank is json to parse the response.
Fill all three blanks to create a load function that fetches user data based on an ID parameter and returns it.
export const load = async ({ [1] }) => {
const res = await fetch(`/api/users/${params.[2]`);
const user = await res.[3]();
return { user };
};The load function destructures params, uses id from params in the URL, and calls json() to parse the response.