Layouts and Components
Table of Contents
- Automatic Layout Chain
- Explicit Layout Selection
- Layout Data Shape
- Reusable Shells
- Shared Components
- SSR-safe Components
Automatic Layout Chain
Vext layouts are React components named layout.tsx under src/frontend/pages/**.
For res.render("admin/dashboard"), Vext can apply the root layout and then the admin layout. The page is rendered inside that chain.
Use layouts for stable page shells: nav, sidebars, account menus, breadcrumbs, and admin chrome.
Explicit Layout Selection
options.layout controls layout behavior.
Use explicit layout selection when two routes in different directories share the same shell, or when an error page should use a minimal shell.
Layout Data Shape
Pass layout data through the third render argument.
Keep layout data small and serializable. Prefer IDs, labels, URLs, and permission flags over raw ORM records.
Reusable Shells
When several layouts share UI, move the UI to src/frontend/components/**.
Then import it from a layout:
Shared Components
Shared components should be browser-safe. They may receive server-prepared props, but they should not import services or Node-only modules.
Put page-specific components near the page only if they are not shared. Put common UI in src/frontend/components/**.
SSR-safe Components
The first render runs on the server and then hydrates in the browser. Avoid first-render differences:
- Do not call
Date.now(),Math.random(), or browser-only APIs during initial render. - Read language from
useVextI18n()or server-provided props. - Read request-specific data from props or
layoutData. - Move browser-only work into
useEffect.
This keeps SSR HTML and browser hydration consistent.