Skip to content

Commit 54259ee

Browse files
authored
docs: create docs for _app.tsx (#494)
1 parent d14b77e commit 54259ee

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

docs/concepts/app-wrapper.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
description: |
3+
Add a global application wrapper to provide common meta tags or context for application routes.
4+
---
5+
6+
An application wrapper is defined in an `_app.tsx` file in `routes/` folder. It
7+
must contain a default export that is a regular Preact component. Only one such
8+
wrapper is allowed per application.
9+
10+
It receives component through props which is to be wrapped. For instance, it
11+
allows to introduce a global container for the whole application.
12+
13+
```tsx
14+
// routes/_app.tsx
15+
16+
import { AppProps } from "$fresh/server.ts";
17+
18+
export default function App({ Component }: AppProps) {
19+
return (
20+
<div class="wrapper">
21+
<Component />
22+
</div>
23+
);
24+
}
25+
```
26+
27+
There is also a possibility to modify the document template by using special
28+
tags `html`, `Head` or `body`. This can be done in any other Preact component,
29+
but using it in the application wrapper lets you define one common document
30+
template.
31+
32+
```tsx
33+
// routes/_app.tsx
34+
35+
import { asset, Head } from "$fresh/runtime.ts";
36+
import { AppProps } from "$fresh/src/server/types.ts";
37+
38+
export default function App({ Component }: AppProps) {
39+
return (
40+
<html data-custom="data">
41+
<Head>
42+
<title>Fresh</title>
43+
<link rel="stylesheet" href={asset("style.css")} />
44+
</Head>
45+
<body class="bodyClass">
46+
<Component />
47+
</body>
48+
</html>
49+
);
50+
}
51+
```
52+
53+
Currently, there is no way of overriding default tags/attributes from provided
54+
template.

docs/toc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
["data-fetching", "Data fetching"],
3030
["deployment", "Deployment"],
3131
["plugins", "Plugins"],
32-
["updating", "Updating Fresh"]
32+
["updating", "Updating Fresh"],
33+
["app-wrapper", "Application wrapper"]
3334
]
3435
},
3536
"integrations": {

0 commit comments

Comments
 (0)