### Install Solid Meta package
Source: https://github.com/solidjs/solid-meta/blob/main/README.md
Use npm to install the @solidjs/meta package into your project.
```bash
npm i @solidjs/meta
```
--------------------------------
### Server-Side Rendering Setup with Solid Meta
Source: https://context7.com/solidjs/solid-meta/llms.txt
Demonstrates how to set up server-side rendering (SSR) with Solid Meta. It involves wrapping the app with `MetaProvider` and using `getAssets` to inject collected tags into the HTML response. This ensures meta tags are correctly rendered on the initial server response.
```jsx
import { renderToString, getAssets } from "solid-js/web";
import { MetaProvider, Title, Meta } from "@solidjs/meta";
function App() {
return (
Server Rendered Page
Hello from the server!
);
}
// Express.js example
app.get("*", (req, res) => {
const html = renderToString(() => );
res.send(`
${getAssets()}
${html}
`);
});
// Output head section will include:
// Server Rendered Page
//
```
--------------------------------
### SolidStart Integration with Solid Meta
Source: https://context7.com/solidjs/solid-meta/llms.txt
Shows how to integrate Solid Meta into a SolidStart application. `MetaProvider` is placed at the router root for global meta tags, with specific routes able to override these defaults. This setup manages meta tags across all application routes effectively.
```jsx
// app.tsx
import { MetaProvider, Title, Meta, Link } from "@solidjs/meta";
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start";
import { Suspense } from "solid-js";
export default function App() {
return (
(
{/* Default meta tags for all pages */}
My SolidStart AppLoading...}>
{props.children}
)}
>
);
}
// routes/products/[id].tsx - Page-specific meta tags override defaults
import { Title, Meta } from "@solidjs/meta";
import { useParams } from "@solidjs/router";
export default function ProductPage() {
const params = useParams();
const product = getProduct(params.id); // Your data fetching logic
return (
<>
{product.name} - My Store
{product.name}
{product.description}
>
);
}
```
--------------------------------
### Initialize MetaProvider and basic head tags
Source: https://context7.com/solidjs/solid-meta/llms.txt
Demonstrates how to wrap an application with MetaProvider and define initial document head tags like Title, Meta, and Link.
```jsx
import { MetaProvider, Title, Meta, Link } from "@solidjs/meta";
import { render } from "solid-js/web";
function App() {
return (
My Application
Welcome to My App
);
}
render(() => , document.getElementById("root"));
```
--------------------------------
### Configure SolidStart application
Source: https://github.com/solidjs/solid-meta/blob/main/README.md
Wrap your application root with the MetaProvider component to enable head tag management within a SolidStart project.
```jsx
import { MetaProvider, Title } from "@solidjs/meta";
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start";
import { Suspense } from "solid-js";
export default function App() {
return (
(
SolidStart - Basic{props.children}
)}
>
);
}
```
--------------------------------
### Configure SEO and social meta tags
Source: https://context7.com/solidjs/solid-meta/llms.txt
Illustrates the usage of the Meta component to define standard SEO tags, Open Graph properties, and responsive theme colors.
```jsx
import { MetaProvider, Meta } from "@solidjs/meta";
function SEOMetaTags() {
return (
Page content here
);
}
```
--------------------------------
### Implement Server-Side Rendering
Source: https://github.com/solidjs/solid-meta/blob/main/README.md
Wrap the application in MetaProvider on the server and use getAssets from solid-js/web to inject collected head tags into the HTML template.
```jsx
import { renderToString, getAssets } from 'solid-js/web';
import { MetaProvider } from '@solidjs/meta';
import App from './App';
const app = renderToString(() =>
);
res.send(`
${getAssets()}
${app}
`);
```
--------------------------------
### Inject Head Tags in Components
Source: https://github.com/solidjs/solid-meta/blob/main/README.md
Use components like Title, Link, and Meta anywhere in your component tree to dynamically update the document head.
```jsx
import { MetaProvider, Title, Link, Meta } from '@solidjs/meta';
const App = () => (
Title of page
);
```
--------------------------------
### Manage head tags with useHead hook
Source: https://context7.com/solidjs/solid-meta/llms.txt
The useHead hook provides low-level access to the head management system, enabling the creation of custom components for complex tags like JSON-LD.
```jsx
import { MetaProvider, useHead } from "@solidjs/meta";
import { createUniqueId } from "solid-js";
function JsonLd(props) {
useHead({
tag: "script",
props: { type: "application/ld+json", children: JSON.stringify(props.data) },
id: createUniqueId()
});
return null;
}
```
--------------------------------
### Use Stylesheet convenience component
Source: https://context7.com/solidjs/solid-meta/llms.txt
The Stylesheet component is a wrapper around the Link component that defaults the rel attribute to 'stylesheet'.
```jsx
import { MetaProvider, Stylesheet } from "@solidjs/meta";
function PageWithStylesheets() {
return (
);
}
```
--------------------------------
### Manage dynamic document titles
Source: https://context7.com/solidjs/solid-meta/llms.txt
Shows how the Title component handles cascading updates and automatic restoration of previous titles when components unmount or state changes.
```jsx
import { MetaProvider, Title } from "@solidjs/meta";
import { createSignal, Show } from "solid-js";
function PageWithDynamicTitle() {
const [showDetails, setShowDetails] = createSignal(false);
return (
My WebsiteProducts - My WebsiteProduct Details - My Website
);
}
```
--------------------------------
### Set base URL with SolidJS Meta
Source: https://context7.com/solidjs/solid-meta/llms.txt
The Base component sets the tag, defining the base URL for all relative URLs within the document.
```jsx
import { MetaProvider, Base, Link } from "@solidjs/meta";
function AppWithBaseURL() {
return (
About
);
}
```
--------------------------------
### Render Link tags with SolidJS Meta
Source: https://context7.com/solidjs/solid-meta/llms.txt
The Link component renders tags for resources like stylesheets, icons, and SEO-related links. It supports multiple instances and does not cascade.
```jsx
import { MetaProvider, Link } from "@solidjs/meta";
function ResourceLinks() {
return (
Page content
);
}
```
--------------------------------
### Inject inline styles with SolidJS Meta
Source: https://context7.com/solidjs/solid-meta/llms.txt
The Style component allows for injecting inline
);
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.