How to pass data from child route to the parent layout? #14240
-
I want to do things like this, in layout file: <!-- +layout.svelte -->
<script>
/** @type {import('./$types').LayoutData} */
let { title } = $props();
</script>
<svelte:head>
<title>{title}</title>
</svelte:head> Then i can set title in the child +layout.svelte or +page.svelte just with a variable. And i don't kown how to implement yet. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I believe that the way to do this today is to either use a store and set it in the context from +layout.svelte with pages updating the store value or to create +page.ts files that return a But the ask here is kind of similar to this discussion on passing data from pages to layouts. |
Beta Was this translation helpful? Give feedback.
-
For page metadata i usually go the route of defining a schema inside
In every export const load = () => {
return {
meta: {
title: 'This is the page title!'
}
}
} A component <script lang="ts">
import { page } from '$app/stores';
const {
title,
...
} = $derived($page.data.meta);
</script>
<svelte:head>
<title>{title}</title>
...
<svelte:head> |
Beta Was this translation helpful? Give feedback.
For page metadata i usually go the route of defining a schema inside
app.d.ts
In every
+page.{ts,js}
file i provide the page metadata:A component
Seo.svelte
which is placed inside the root layout takes care of rendering the metadata: