I am trying the first project with Svelte and I have a situation like this:
I fetch a list of results from an API like here:
# Page with a list of items
<script context="module">
export const load = async ({ page, fetch }) => {
const res = await fetch(`url`);
const items = await res.json();
return {
props: {
items,
},
};
};
</script>
<script>
export let items;
</script>
{#each items.data as { id, item, href }}
<li>
<a href="/page/{href}">{ item }</a>
</li>
{/each}
I am trying to pass multiple parameters to the next (dynamic) route so that href is the slug and id is the id for fetching the item details from the API like here:
# Page with a single item
<script context="module">
export const load = async ({ page, fetch }) => {
const slug = page.params.slug; <-- I can get this
const res = await fetch(`url/${page.id}`); <-- but not this
const data = await res.json();
return {
props: {
data,
},
};
};
</script>
I apologise for my ignorance but I am really struggling and I do not know how to address this exactly. I would appreciate any hints.