goto
in SvelteKit, issues related to layouts often arise from how SvelteKit handles page and layout updates during navigation. Here are common problems and solutions:load
function to re-run, even if data within the layout is expected to change based on the new route. This often happens when only page-specific parameters change, and SvelteKit deems the layout's dependencies unaffected.invalidate()
. If your layout's load
function fetches data from an API endpoint, you can invalidate that endpoint's URL to force the layout's load
function to re-run.invalidateAll: true
and Layout Update Order:goto("...", { invalidateAll: true })
might navigate to the destination page before the parent layout has fully updated, leading to issues if the child page relies on data from the updated layout.invalidateAll()
with goto()
using a promise:+page.svelte
files.+page@.svelte
+p...@segmentName.svelte
(e.g., +p...@admin.svelte
for a page within /admin
that should use /admin/+layout.svelte
even if there are deeper layouts).goto
Not Triggering Load Functions Predictably:goto
might not reliably re-run page load
functions if SvelteKit determines that no relevant dependencies have changed, even if URL parameters are different.invalidate()
before or after the goto
call to ensure the load
function re-runs and fetches fresh data.invalidate
or layout-breaking techniques, you can effectively manage layout behavior when using goto
in SvelteKit.