admin管理员组文章数量:1125475
I use layout.server.js
to perform url checks and load other data. This data is loaded by +page.svelte
. Now I want to load current url in +layout.svelte
for page transition, but the data loaded (let { data } = $props();
) in +layout.svelte
is empty while it is correctly loaded in +page.svelte
.
//(app)/+layout.server.js
export async function load({ url }) {
//...some code
return { myData, url: url.pathname };
}
//(app)/+page.svelte
let { data } = $props(); // returns the correct data
//src/+layout.svelte
<script>
let { children, data } = $props(); // undefined
</script>
{#key data.url}
<main in:fade={{ duration: 300, delay: 300 }} out:fade={{ duration: 300 }}>
{@render children?.()}
</main>
{/key}
What am I missing ?
Thx,
I use layout.server.js
to perform url checks and load other data. This data is loaded by +page.svelte
. Now I want to load current url in +layout.svelte
for page transition, but the data loaded (let { data } = $props();
) in +layout.svelte
is empty while it is correctly loaded in +page.svelte
.
//(app)/+layout.server.js
export async function load({ url }) {
//...some code
return { myData, url: url.pathname };
}
//(app)/+page.svelte
let { data } = $props(); // returns the correct data
//src/+layout.svelte
<script>
let { children, data } = $props(); // undefined
</script>
{#key data.url}
<main in:fade={{ duration: 300, delay: 300 }} out:fade={{ duration: 300 }}>
{@render children?.()}
</main>
{/key}
What am I missing ?
Thx,
Share Improve this question edited yesterday 16ar asked 2 days ago 16ar16ar 1752 silver badges13 bronze badges1 Answer
Reset to default 0Is the +layout.svelte safely in the same folder as the +layout.server.js and the +page.svelte? That would be the first thing that comes to mind, because I once had a case where I didn't see that because the file manager in the code editor had such extremely small indentations. If they are, have you tried building the application (npm run build) and running it in the production version (npm run preview)? Otherwise, I would also try deleting the .svelte-kit folder and deleting and reinstalling node_modules.
本文标签: sveltekitPass data from layoutserverjs to layoutsvelte and pagesvelteStack Overflow
版权声明:本文标题:sveltekit - Pass data from +layout.server.js to +layout.svelte and +page.svelte - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736666080a1946669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论