From 54259ee9eec489864da80a81cf71b1f3221edadf Mon Sep 17 00:00:00 2001 From: harrel56 Date: Tue, 7 Mar 2023 19:24:21 +0100 Subject: [PATCH] docs: create docs for _app.tsx (#494) --- docs/concepts/app-wrapper.md | 54 ++++++++++++++++++++++++++++++++++++ docs/toc.json | 3 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 docs/concepts/app-wrapper.md diff --git a/docs/concepts/app-wrapper.md b/docs/concepts/app-wrapper.md new file mode 100644 index 00000000..20df8056 --- /dev/null +++ b/docs/concepts/app-wrapper.md @@ -0,0 +1,54 @@ +--- +description: | + Add a global application wrapper to provide common meta tags or context for application routes. +--- + +An application wrapper is defined in an `_app.tsx` file in `routes/` folder. It +must contain a default export that is a regular Preact component. Only one such +wrapper is allowed per application. + +It receives component through props which is to be wrapped. For instance, it +allows to introduce a global container for the whole application. + +```tsx +// routes/_app.tsx + +import { AppProps } from "$fresh/server.ts"; + +export default function App({ Component }: AppProps) { + return ( +
+ +
+ ); +} +``` + +There is also a possibility to modify the document template by using special +tags `html`, `Head` or `body`. This can be done in any other Preact component, +but using it in the application wrapper lets you define one common document +template. + +```tsx +// routes/_app.tsx + +import { asset, Head } from "$fresh/runtime.ts"; +import { AppProps } from "$fresh/src/server/types.ts"; + +export default function App({ Component }: AppProps) { + return ( + + + Fresh + + + + + + + ); +} +``` + +Currently, there is no way of overriding default tags/attributes from provided +template. diff --git a/docs/toc.json b/docs/toc.json index 96d28a90..57c28365 100644 --- a/docs/toc.json +++ b/docs/toc.json @@ -29,7 +29,8 @@ ["data-fetching", "Data fetching"], ["deployment", "Deployment"], ["plugins", "Plugins"], - ["updating", "Updating Fresh"] + ["updating", "Updating Fresh"], + ["app-wrapper", "Application wrapper"] ] }, "integrations": {