Skip to main content
A _layout.tsx file wraps every page in that directory and below. Layouts compose: src/routes/_layout.tsx wraps src/routes/users/_layout.tsx wraps users/[id].tsx.
src/routes/_layout.tsx
Do not return <html> or <body> from a layout. That belongs in _document.tsx. A layout that emits a second <html> produces invalid markup and breaks hydration.

Layout loaders

Pair a layout with _layout.server.tsx to load shared data (current user, workspace, nav counts). The returned object is passed as props to that layout only — not to child pages. Pages still need their own loader if they need the same data.
src/routes/_layout.server.tsx
src/routes/_layout.tsx
redirect() from a layout loader works. A common pattern is: public marketing layout at src/routes/(marketing)/_layout.tsx, authenticated layout at src/routes/(app)/_layout.tsx that redirects to /login. Layout loaders run before the page loader, outside-in.

Document

Layouts wrap the page inside #app. The optional src/routes/_document.tsx wraps the full HTML response (<html>, <head>, scripts). The file is optional. If you omit it, the plugin uses a default shell. For step-by-step setup, global CSS, and required props, see the Document (_document) guide. Client <Link> SPA navigations do not re-render the document — they only swap #app.

Errors and 404

_error.tsx and _404.tsx are not layouts. They replace the page (no layout wrappers). See Errors.