docs: improve examples and fix app wrapper (#1244)
This commit is contained in:
@@ -23,32 +23,3 @@ export default function App({ Component }: AppProps) {
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
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 (
|
||||
<html data-custom="data">
|
||||
<Head>
|
||||
<title>Fresh</title>
|
||||
<link rel="stylesheet" href={asset("style.css")} />
|
||||
</Head>
|
||||
<body class="bodyClass">
|
||||
<Component />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Currently, there is no way of overriding default tags/attributes from provided
|
||||
template.
|
||||
|
||||
@@ -8,4 +8,4 @@ that you may like in your Fresh project. If there's a specific example you'd
|
||||
like to see here, please open
|
||||
[a GitHub discussion](https://github.com/denoland/fresh/discussions/new?category=ideas).
|
||||
|
||||
- [Modifying the `<head>` Element](modifying-the-head-element)
|
||||
- [Modifying the `<head>`](./examples/modifying-the-head)
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
---
|
||||
description: |
|
||||
By adding inner components to Fresh's head element, we add inner components to the HTML head element of the web page.
|
||||
Add components like <title> or <meta> to a <head> tag using Fresh's <Head> component.
|
||||
---
|
||||
|
||||
We can use the `<Head />` component in `$fresh/runtime.ts` to modify the
|
||||
`<head>` element. By adding inner components to `<Head />`, we add inner
|
||||
components to the `<head>` element of the web page. Some uses include:
|
||||
We can use the `<Head />` component in `$fresh/runtime.ts` to add elements as
|
||||
children of the `<head>` element. By adding elements as children of Fresh's
|
||||
`<Head />` tag, these automatically get injected into the `<head>` element of
|
||||
the web page. Some uses include:
|
||||
|
||||
- Setting the document title using `<title>`
|
||||
- Specifying page metadata using `<meta>`
|
||||
- Linking to external resources using `<link>`
|
||||
- Including JavaScript code using `<script>`
|
||||
- Linking to resources like stylesheets using `<link>`
|
||||
- Including third-party JavaScript code using `<script>`
|
||||
|
||||
```tsx
|
||||
// routes/index.tsx
|
||||
+1
-3
@@ -39,8 +39,6 @@
|
||||
},
|
||||
"examples": {
|
||||
"title": "Examples",
|
||||
"pages": [
|
||||
["modifying-the-head-element", "Modifying the Head Element"]
|
||||
]
|
||||
"pages": [["modifying-the-head", "Modifying the <head>"]]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user