Complete the code to export a server load function in +page.server.js.
export const load = async ([1]) => { return { message: 'Hello from server!' }; };
The server load function receives an event object that contains request details.
Complete the code to access URL search parameters inside the server load function.
export const load = async (event) => {
const id = event.url.[1].get('id');
return { id };
};The url.searchParams property gives access to URL query parameters.
Fix the error in the server load function to correctly return data.
export const load = async (event) => {
const data = await fetch('/api/data');
const json = await data.[1]();
return { json };
};The Response object has a json() method to parse JSON data.
Fill both blanks to destructure parameters and return a custom object in the server load function.
export const load = async ([1]) => { const { params } = [2]; return { id: params.id }; };
The event object contains params for route parameters.
Fill all three blanks to fetch data, parse JSON, and return it in the server load function.
export const load = async ([1]) => { const response = await fetch('/api/items'); const data = await response.[2](); return { [3] }; };
The parameter is event, the method to parse JSON is json(), and the returned object uses data.