Skip to content

Commit c19c1a8

Browse files
authored
Merge pull request #43 from royeden/patch-1
docs(solid-start): Adds SolidStart example into `README.md`
2 parents f4954fe + 76aeb3d commit c19c1a8

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,50 @@ npm i @solidjs/meta
2727

2828
On the server, the tags are collected, and then on the client the server-generated tags are removed in favor of the client-rendered tags so that SPAs still work as expected (e.g. in cases where subsequent page loads need to change the head tags).
2929

30+
31+
> [!IMPORTANT]
32+
> Be sure to avoid adding any normal `<title />` tags in any server files (be it `entry-server.jsx|tsx` in SolidStart projects or inside your server file), as they would override the functionality of `@solid/meta`!
33+
34+
35+
### SolidStart setup
36+
37+
1. Wrap your app with `<MetaProvider />` inside of the `root` of the `<Router />` component.
38+
2. You can optionally provide a `<title />` fallback by providing a `<Title />` component inside of `<MetaProvider />`.
39+
40+
#### `app.jsx` / `app.tsx`
41+
```jsx
42+
// @refresh reload
43+
import { MetaProvider, Title } from "@solidjs/meta";
44+
import { Router } from "@solidjs/router";
45+
import { FileRoutes } from "@solidjs/start";
46+
import { Suspense } from "solid-js";
47+
import "./app.css";
48+
49+
export default function App() {
50+
return (
51+
<Router
52+
root={props => (
53+
<MetaProvider>
54+
<Title>SolidStart - Basic</Title>
55+
<a href="/">Index</a>
56+
<a href="/about">About</a>
57+
<Suspense>{props.children}</Suspense>
58+
</MetaProvider>
59+
)}
60+
>
61+
<FileRoutes />
62+
</Router>
63+
);
64+
}
65+
```
66+
67+
---
68+
3069
### Server setup
3170

3271
Wrap your app with `<MetaProvider />` on the server, using a `tags[]` array to pass down as part of your server-rendered payload. When rendered, the component mutates this array to contain the tags.
3372

34-
```js
73+
```jsx
3574
import { renderToString, getAssets } from 'solid-js/web';
3675
import { MetaProvider } from '@solidjs/meta';
3776
import App from './App';
@@ -60,7 +99,7 @@ res.send(`
6099

61100
There is nothing special required on the client, just render one of head tag components whenever you want to inject a tag in the `<head />`.
62101

63-
```js
102+
```jsx
64103
import { MetaProvider, Title, Link, Meta } from '@solidjs/meta';
65104

66105
const App = () => (

0 commit comments

Comments
 (0)