|
1 | 1 | --- |
2 | 2 | title: Link |
3 | 3 | order: 2 |
4 | | -use_cases: "adding favicon, stylesheets, external resources, preloading assets, web fonts" |
| 4 | +use_cases: >- |
| 5 | + links, favicons, stylesheets, preloads, external resources |
5 | 6 | tags: |
6 | 7 | - link |
7 | | - - favicon |
8 | | - - stylesheet |
9 | | - - assets |
10 | 8 | - head |
11 | 9 | - resources |
| 10 | + - component |
12 | 11 | version: "1.0" |
13 | 12 | description: >- |
14 | | - Add external resources like stylesheets and favicons to your Solid app. Learn |
15 | | - to use the Link component for optimal resource loading and icons. |
| 13 | + Link renders a link element through Solid Meta. |
16 | 14 | --- |
17 | 15 |
|
18 | | -The Link component establishes a connection between the page and an external resource. |
19 | | -Commonly, this is used for linking stylesheets and other associations. |
| 16 | +`Link` adds a [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) element that defines a relationship between the document and an external resource. |
20 | 17 |
|
21 | | -This component renders a [`link`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) element within the document's `<head>`. |
| 18 | +## Import |
22 | 19 |
|
23 | | -```tsx twoslash |
| 20 | +```tsx |
24 | 21 | import { Link } from "@solidjs/meta"; |
25 | | -<Link rel="icon" href="/favicon.ico" />; |
26 | 22 | ``` |
27 | 23 |
|
28 | | -## Usage |
| 24 | +## Type |
29 | 25 |
|
30 | | -### Adding a favicon |
31 | | - |
32 | | -To add a favicon in an app, `<Link>` can be used to point to the asset: |
| 26 | +```tsx |
| 27 | +const Link: Component<JSX.LinkHTMLAttributes<HTMLLinkElement>>; |
| 28 | +``` |
33 | 29 |
|
34 | | -```tsx twoslash |
35 | | -import { MetaProvider, Link } from "@solidjs/meta"; |
| 30 | +## Props |
36 | 31 |
|
37 | | -export default function Root() { |
38 | | - return ( |
39 | | - <MetaProvider> |
40 | | - <Link rel="icon" href="/favicon.ico" /> |
41 | | - </MetaProvider> |
42 | | - ); |
43 | | -} |
44 | | -``` |
| 32 | +Accepts attributes for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link). |
45 | 33 |
|
46 | | -### Using an emoji as a favicon |
| 34 | +## Behavior |
47 | 35 |
|
48 | | -To use an emoji as a favicon, first create a function that returns a data URI containing an SVG image: |
| 36 | +- Registers a self-closing `link` tag. |
| 37 | +- Non-cascading tags can add one document-head element per active instance. |
| 38 | +- Requires [`MetaProvider`](/solid-meta/reference/meta/metaprovider) in the component tree. |
49 | 39 |
|
50 | | -```jsx |
51 | | -const emojiSvg = (emoji) => { |
52 | | - return ( |
53 | | - `data:image/svg+xml;utf8,` + |
54 | | - `<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>${emoji}</text></svg>` |
55 | | - ); |
56 | | -}; |
57 | | -``` |
| 40 | +## Examples |
58 | 41 |
|
59 | | -Following this, include the emoji as an argument within that function in the `href` property of the Link component: |
| 42 | +### Basic usage |
60 | 43 |
|
61 | | -```jsx |
| 44 | +```tsx |
62 | 45 | import { MetaProvider, Link } from "@solidjs/meta"; |
63 | 46 |
|
64 | | -export default function Root() { |
| 47 | +function App() { |
65 | 48 | return ( |
66 | 49 | <MetaProvider> |
67 | | - <Link rel="icon" href={emojiSvg("😎")} /> |
| 50 | + <Link rel="icon" href="/favicon.ico" /> |
68 | 51 | </MetaProvider> |
69 | 52 | ); |
70 | 53 | } |
71 | 54 | ``` |
| 55 | + |
| 56 | +## Related |
| 57 | + |
| 58 | +- [`MetaProvider`](/solid-meta/reference/meta/metaprovider) |
| 59 | +- [`useHead`](/solid-meta/reference/meta/use-head) |
0 commit comments