pass stuff to layout SvelteKit #deprecated

Svelte

5/25/2022, 9:18:59 PM

by Leo Voon

Can the child element pass a prop back to the parent? For instance, a component could export a title prop to its layout, which would in turn set the page’s title.

For example, in your child component,

<script context="module">
	export const load = async ({props}) => {
	  return {
		props,
		stuff: { title: props.title}
	  }
	}
</script>

then consume as ..

// __layout.svelte

<svelte:head>
<title>{$page.stuff.title} </title>
</svelte:head>

however, this might not last..

https://github.com/sveltejs/kit/issues/4911