I am trying to create a dynamically updating navbar in SvelteKit, with the currently open section formatted accordingly. I am attempting to identify the page based on the first part of the path, as below:
__layout.svelte:
<script context="module">
export const load = ({ page }) => {
return {
props: {
currentSection: `${page.path}`.split('/')[0],
sections: ['home', 'dashboard', 'settings']
}
};
}
</script>
<div class="min-h-screen bg-gray-100">
<Header {...props} />
<slot />
</div>
Header.svelte
<script>
import Menu from "$lib/nav/menu.svelte"
</script>
<Menu {...props}></Menu>
Menu.svelte
<script>
export let sections;
export let currentSection;
</script>
{#each sections as { section }}
<a
href="/{section}"
class="{section == currentSection
? 'bg-gray-900 text-white'
: 'text-gray-300 hover:bg-gray-700'} other-classes"
>{section}</a
>
{/each}
This is resulting in a props is not defined error, but I would have expected props to be defined since I've defined it in the return from the load() fundtion on the primary layout (based on the docs).
Do I somehow need to explicitly declare the props rather than expecting them to be available from the return of the load() function?