Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
Tutorial , 3. Layouts
The layout is the chrome around every page, header, navigation, footer, theme toggle, that persists across client navigations. We will flesh out the root layout and add a theme toggle (which we will wire to state in the next step).
The root layout
pages/layout.tsx wraps every page via the layouts option in createApp. It receives children (the
current page):
Because the layout is outside the page component, it does not unmount on navigation, the header and footer stay mounted while the page swaps. That is what makes navigation feel instant and lets state held in the layout (or in atoms it reads) persist.
A theme toggle component (stubbed for now)
The layout tree (for later)
createApp({ layouts }) takes a tree keyed by path segment, so you can give different sections different
chrome. The root key is "":
For Notes one root layout is enough; the full nesting model is in Layouts.
Error and not-found pages
Two more convention pages round out the chrome:
Wire them in server.tsx:
See Error & not-found.
Styling the chrome
Run it
Navigate between / and a note: the header/footer stay; only the <main> content changes. The theme button
does nothing yet, that is the next step.
Next: make the toggle (and the notes) real with state, 4. State with Mimir.