Layouts, Error, and Not Found Pages
Dinou uses a nested routing system. Layouts, error pages, and not found pages cascade down the directory hierarchy.
Layouts (layout.tsx)
Layouts wrap pages and child layouts. They persist across navigation, preserving state and preventing unnecessary re-renders.
A layout receives children, params, and any parallel slots (e.g., sidebar) as props. Note: searchParams are not passed to layouts.
// src/dashboard/layout.tsx
export default async function Layout({ children, params, sidebar }) {
return (
<div className="dashboard-grid">
<aside>{sidebar}</aside>
<main>
<h1>Dashboard for {params.teamId}</h1>
{children}
</main>
</div>
);
}Layouts are nested by default. For example, a page at src/dashboard/settings/page.tsx would be wrapped by the root layout (src/layout.tsx) if exists and the dashboard layout (src/dashboard/layout.tsx).
Fetching Data in Layouts
getProps in page_functions.ts to inject data into the root layout for a specific page.Error Handling (error.tsx)
Define an error.tsx file to handle errors in a route segment. Dinou renders the closest error.tsx bubbling up the hierarchy.
It receives error (object) and params as props. Error pages can be Server or Client Components.
// src/some/route/[slug]/error.tsx
"use client"; // Optional: Can be Server Component too
export default function Page({ error, params }) {
return (
<div>
<h2>Something went wrong in {params.slug}!</h2>
<p>{`${error.name}: ${error.message}`}</p>
{error.stack && (
<pre style={{ background: "#eee", padding: "1rem" }}>{error.stack}</pre>
)}
</div>
);
}error.stack is only available in development, not production.
Not Found (not_found.tsx)
Define a not_found.tsx file to customize the 404 UI. Dinou renders the closest not_found.tsx traversing up from the requested URL.
It receives params as a prop. Use useSearchParams() in Client Components, or getContext().req.query in Server Components for search parameters.
Like errors, not found pages cascade through the hierarchy for consistent UX.
Advanced Layout Control (Flags)
Use empty "flag files" (no extension) to control layout behavior, such as breaking out of the nested hierarchy.
| Flag File | Applies To | Description |
|---|---|---|
| reset_layout | layout.tsx | Resets the layout tree. This layout becomes the new root, ignoring parents. |
| no_layout | page.tsx, error.tsx, not_found.tsx | Prevents any layout from wrapping this component. |
| no_layout_error | error.tsx | Prevents layouts for the error page only. |
| no_layout_not_found | not_found.tsx | Prevents layouts for the not found page only. |
src/marketing/reset_layout (empty file)
Result: Ignores global root layout (
src/layout.tsx).Show Technical Details (for Ejected Code)
In the ejected core, the layout resolving and flag checks are implemented in dinou/core/get-jsx.js:
no_layoutcheck: Before crawling layouts, the engine runs a quick search for ano_layoutflag in the page folder. If it exists, it immediately returns the raw Page JSX, bypassing the layout wrapper pipeline entirely.- Layout Traversal &
reset_layoutcheck: If not bypassed, it crawls the directory hierarchy upwards from the page folder, collecting alllayout.tsxpaths. It wraps them from the bottom up. Inside this loop, it checks for areset_layoutflag file in each layout's directory. If found, it wraps in that layout and immediatelybreaksthe loop, skipping all remaining parent layouts.