Advanced: Region Inheritance
Learn how to use SvelteKit's load function hierarchy to inherit, override, and extend regions across nested layouts and pages.
Section Navigation
- Overview
- Getting Started
- Advanced Topics
Source: child page
This data was overridden by +page.server.ts
New Region Added by Page
This region only exists because the page defined it
How It Works
SvelteKit's parent() function allows child load functions to access data from parent
layouts. We use this to create a flexible inheritance system for regions:
- Inherit: Child pages automatically receive all parent regions
- Override: Child can redefine a region with the same name
- Add: Child can define new regions alongside inherited ones
The Pattern
1. Parent Layout Defines Regions
The parent layout's load function defines initial region data that will be available to all child pages.
2. Child Page Inherits and Modifies
The page calls await parent() to get parent data, then uses the spread operator to
inherit regions before defining its own.
3. Layout Defines Region Slots
The layout defines where regions appear. The same <LayoutRegion> components receive different data depending on which page is active.
Key Concepts
Inheritance (Blue)
The sharedNav region is defined in the parent layout and inherited by the page without modification. It appears on all pages in this section.
Override (Purple)
The layoutInfo region is defined in the parent layout but overridden by the page. The page spreads parent regions first, then redefines this region with new data.
Addition (Green)
The pageOnlyRegion doesn't exist in the parent layout. It's defined only by this page, demonstrating how pages can add new regions alongside inherited ones.
Order Matters
Correct
regions: {
...(parentData.regions || {}),
layoutInfo: { /* override */ }
}Wrong
regions: {
layoutInfo: { /* override */ },
...(parentData.regions || {})
// This erases your override!
}When to Use This Pattern
- Multi-level layouts: When you have nested route structures like
/products/[category]/[id] - Section-wide data: When all pages in a section share common regions (navigation, breadcrumbs, etc.)
- Progressive enhancement: When child pages need to extend or modify parent data while preserving some of it
- Flexible overrides: When some pages need to completely replace parent regions while others keep them
Learn More
No footer data provided - showing fallback content.