File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed
Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 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" : {
You can’t perform that action at this time.
0 commit comments