Consider a SvelteKit app with a +layout.svelte file in the src/routes folder. What happens to the nested pages inside this folder?
Think about how layouts provide a common wrapper for pages.
The +layout.svelte file acts as a wrapper for all nested pages in its folder. The nested pages' content is inserted where the <slot /> is placed inside the layout.
Given a +layout.svelte with a reactive variable count that increments every second, and nested pages rendered inside the layout's <slot />, what will the user see?
<script> let count = 0; const interval = setInterval(() => count++, 1000); $: console.log(count); </script> <header>Count: {count}</header> <slot />
Layouts are components and can have reactive state like any Svelte component.
The reactive variable count updates every second, so the header inside the layout updates accordingly. The nested pages remain visible inside the <slot />.
Which option contains the correct syntax for including a <slot /> in a +layout.svelte file?
<script> export let title = 'My App'; </script> <header>{title}</header> <!-- slot goes here -->
Remember that <slot /> is a self-closing tag in Svelte.
In Svelte, <slot /> is the correct self-closing syntax. Using <slot> without closing or double slots is invalid.
A developer created a +layout.svelte with a header and forgot to add a <slot />. What will happen when visiting nested pages?
<header>Site Header</header> <!-- missing slot here -->
Think about how layouts show nested page content.
Without a <slot />, the layout does not have a place to insert nested page content, so it won't appear.
In SvelteKit, if you have a +layout.svelte and a +page.svelte in the same folder, what is the relationship between them when rendering the page?
Think about how layouts provide a frame for pages.
The +layout.svelte acts as a wrapper component. It renders the nested +page.svelte content inside its <slot />, so the page content appears inside the layout.