I'm trying to get the name of a game from the page parameters. I was expecting that the load function would get the location of the game and return it to the page but instead when I ran the code below I got this error:
Cannot read property 'slug' of undefined
This is the code that I am trying to run:
<script context="module">
/** @type {import('@sveltejs/kit').Load} */
export async function load({ params, fetch, session, stuff }) {
let request = await fetch("/json/games.json");
let games = await request.json();
let game = games[params.slug];
if (game && game.location) {
return {
props: {
game: game.location
}
}
} else {
return {
status: 404,
error: "The game could not be found"
}
}
}
</script>
<script>
export let game;
</script>
<svelte:head>
<title>Game</title>
</svelte:head>
<p>Location of Game:</p>
<p>{game}</p>
/src/routes/games/[slug].svelte
. Is that the case? - Thomas Hennessrc/routes/game/[slug].svelte
) - Bob Fanger