0

Given this +layout.svelte:

<div class="app">
    <Header />
    
    <main>
        {@render children()}
    </main>
</div>

if I do a goto in a component, the Header does not refresh (as i think svelte thinks only the children can change). how can I make the Header refresh as well?

note that in the Header i have some code that uses page so i was thinking full reactivity should kick (if Header depends on page.url it should refresh if page.url changes but that is not happening)

Header.svelte:

const init = async () => {
    if (page.url.pathname === '/error') {
        // do something
    }       
}

onMount(init)

1 Answer 1

0

onMount only runs... on mount.

Unless you switch to a route with a different layout, this only happens once since the component stays mounted. If you want this to run on change, you need an $effect instead. (effects also initially run when the components mount and can thus often replace an onMount call.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.