Expand description
§Leptos Meta
Leptos Meta allows you to modify content in a document’s <head>
from within components
using the Leptos
web framework.
Document metadata is updated automatically when running in the browser. For server-side
rendering, after the component tree is rendered to HTML, ServerMetaContextOutput::inject_meta_context
will inject meta tags into a stream of HTML inside the <head>
.
use leptos::prelude::*;
use leptos_meta::*;
#[component]
fn MyApp() -> impl IntoView {
// Provides a [`MetaContext`], if there is not already one provided.
provide_meta_context();
let (name, set_name) = create_signal("Alice".to_string());
view! {
<Title
// reactively sets document.title when `name` changes
text=move || name.get()
// applies the `formatter` function to the `text` value
formatter=|text| format!("“{text}” is your name")
/>
<main>
<input
prop:value=move || name.get()
on:input=move |ev| set_name.set(event_target_value(&ev))
/>
</main>
}
}
§Feature Flags
ssr
Server-side rendering: Generate an HTML string (typically on the server)tracing
Adds integration with thetracing
crate.
Important Note: If you’re using server-side rendering, you should enable ssr
.
Structs§
- Body
Props - Props for the
Body
component. - Formatter
- A function that is applied to the text value before setting
document.title
. - Hashed
Stylesheet Props - Props for the
HashedStylesheet
component. - Html
Props - Props for the
Html
component. - Link
Props - Props for the
Link
component. - Meta
Context - Contains the current state of meta tags. To access it, you can use
use_head
. - Meta
Props - Props for the
Meta
component. - Meta
Tags Props - Props for the
MetaTags
component. - Script
Props - Props for the
Script
component. - Server
Meta Context - Allows you to add
<head>
content from components located in the<body>
of the application, which can be accessed during server rendering viaServerMetaContextOutput
. - Server
Meta Context Output - Allows you to access
<head>
content that was inserted viaServerMetaContext
. - Style
Props - Props for the
Style
component. - Stylesheet
Props - Props for the
Stylesheet
component. - Title
Context - Contains the current state of the document’s
<title>
. - Title
Props - Props for the
Title
component.
Functions§
- Body
- A component to set metadata on the document’s
<body>
element from within the application. - Hashed
Stylesheet - Injects an
HTMLLinkElement
into the document head that loads acargo-leptos
-hashed stylesheet. - Html
- A component to set metadata on the document’s
<html>
element from within the application. - Link
- Injects an
HTMLLinkElement
into the document head, accepting any of the valid attributes for that tag. - Meta
- Injects an
HTMLMetaElement
into the document head to set metadata - Meta
Tags - During server rendering, inserts the meta tags that have been generated by the other components
in this crate into the DOM. This should be placed somewhere inside the
<head>
element that is being used during server rendering. - Script
- Injects an
HTMLScriptElement
into the document head, accepting any of the valid attributes for that tag. - Style
- Injects an
HTMLStyleElement
into the document head, accepting any of the valid attributes for that tag. - Stylesheet
- Injects an
HTMLLinkElement
into the document head that loads a stylesheet from the URL given by thehref
property. - Title
- A component to set the document’s title by creating an
HTMLTitleElement
. - provide_
meta_ context - Provides a
MetaContext
, if there is not already one provided. This ensures that you can provide it at the highest possible level, without overwriting aMetaContext
that has already been provided (for example, by a server-rendering integration.) - use_
head - Returns the current
MetaContext
.