pub fn Title(props: TitleProps) -> impl IntoView
Expand description
A component to set the document’s title by creating an HTMLTitleElement
.
The title
and formatter
can be set independently of one another. For example, you can create a root-level
<Title formatter=.../>
that will wrap each of the text values of <Title/>
components created lower in the tree.
use leptos::prelude::*;
use leptos_meta::*;
#[component]
fn MyApp() -> impl IntoView {
provide_meta_context();
let formatter = |text| format!("{text} — Leptos Online");
view! {
<main>
<Title formatter/>
// ... routing logic here
</main>
}
}
#[component]
fn PageA() -> impl IntoView {
view! {
<main>
<Title text="Page A"/> // sets title to "Page A — Leptos Online"
</main>
}
}
#[component]
fn PageB() -> impl IntoView {
view! {
<main>
<Title text="Page B"/> // sets title to "Page B — Leptos Online"
</main>
}
}
§Optional Props
- mut formatter:
impl Into<Formatter>
- A function that will be applied to any text value before it’s set as the title.
- mut text:
impl Into<TextProp>
- Sets the current
document.title
.
- Sets the current