Skip to content

Should the __layout load called earlier than Page load ? #4374

Answered by geoffrich
itssumitrai asked this question in Q&A
Discussion options

You must be logged in to vote

What makes you say that the index load function is called first? If you have the following...

<!-- __layout.svelte -->
<script context="module">
	export function load() {
		console.log('layout load');
		return {};
	}

</script>

<main>
	<slot />
</main>

<!-- index.svelte -->
<script context="module">
	export function load() {
		console.log('page load');
		return {};
	}
</script>

<h1>Hello world</h1>

... and navigate to localhost:3000, the console will log the following:

layout load
page load

So the __layout load function is executed first, then the page. Do you have an example where that isn't happening?

This matches how the docs talk about stuff as being something that's passed from a…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Rich-Harris
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mrkishi
Comment options

You must be logged in to vote
1 reply
@geoffrich
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants