feat: support route layouts via _layout.tsx (#1506)

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
Michael Gearhardt
2023-07-26 11:49:08 +02:00
committed by GitHub
co-authored by Marvin Hagemeister
parent 18857ea052
commit 1ed93cec88
27 changed files with 397 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
---
description: |
Add a route layout to provide common meta tags, context for application sub routes, and common layout.
---
An route layout is defined in a `_layout.tsx` file in any sub directory (at any
level) under the `routes/` folder. It must contain a default export that is a
regular Preact component. Only one such layout is allowed per sub directory.
The component to be wrapped is received via props, in addition to a few other
things. This allows for the introduction of a global container functioning as a
template which can be conditioned based on state and params. Note that any state
set by middleware is available via `props.state`.
```tsx
// routes/sub/_layout.tsx
import { LayoutProps } from "$fresh/server.ts";
export default function Layout({ Component, state }: LayoutProps) {
//do something with state here
return (
<div class="layout">
<Component />
</div>
);
}
```
+1
View File
@@ -58,6 +58,7 @@ const toc: RawTableOfContents = {
["plugins", "Plugins", "link:latest"],
["updating", "Updating Fresh", "link:canary"],
["app-wrapper", "Application wrapper", "link:latest"],
["route-layout", "Route layouts", "link:canary"],
["server-configuration", "Server configuration", "link:latest"],
],
},