Consider a route component in Deno Fresh that returns this JSX:
export default function Page() {
return (
Welcome to Fresh!
This is the home page.
);
}What will the user see when visiting this route?
export default function Page() {
return (
<main>
<h1>Welcome to Fresh!</h1>
<p>This is the home page.</p>
</main>
);
}Look at what JSX elements are returned inside the main tag.
The component returns a main element containing both a heading and a paragraph, so both appear on the page.
Given this nested layout structure:
routes/
(app)/
_layout.tsx
dashboard/
_layout.tsx
index.tsxIf the root _layout.tsx renders a header with 'App Header' and the dashboard layout renders a sidebar with 'Dashboard Sidebar', what will be visible when visiting /dashboard?
/* Root layout */ export default function RootLayout({ children }) { return ( <> <header>App Header</header> {children} </> ); } /* Dashboard layout */ export default function DashboardLayout({ children }) { return ( <> <aside>Dashboard Sidebar</aside> {children} </> ); } /* Dashboard page */ export default function DashboardPage() { return <main>Dashboard Content</main>; }
Think about how nested layouts wrap their children in Fresh.
Nested layouts wrap their children, so the root layout renders the header, then the dashboard layout renders the sidebar, then the page renders its content.
Layouts in Deno Fresh must export a default function that accepts a children prop. Which of these options is syntactically correct for a layout?
Remember the layout must be a default export and receive children as a prop.
Option C correctly defines a default exported function with destructured children prop and returns it inside a div.
Option C is not a default export.
Option C treats children as a positional argument, which is incorrect.
Option C uses props.child instead of children.
Given this dashboard layout code:
export default function DashboardLayout() {
return (
<>
>
);
}When visiting /dashboard, the sidebar shows but the page content does not. What is the cause?
export default function DashboardLayout() {
return (
<>
<aside>Dashboard Sidebar</aside>
</>
);
}Layouts must render their children to show nested page content.
The layout component must accept a children prop and include it in the returned JSX. Without it, the nested page content is not rendered.
In Deno Fresh, routes can be nested inside folders with layout files. How does Fresh decide which layout(s) to apply when rendering a page?
Think about how nested folders and layouts work together.
Fresh applies layouts hierarchically, starting from the root layout and nesting down through each folder's layout until the route, so all layouts wrap the page content in order.
