Module bounce::helmet

source ·
Available on crate feature helmet only.
Expand description

A module to manipulate common tags under the <head /> element.

The Helmet component supports the following elements:

  • title
  • style
  • script
  • base
  • link
  • meta

The Helmet component supports setting attributes of the following elements:

  • html
  • body

Example

use bounce::helmet::{Helmet, HelmetBridge};

#[function_component(PageA)]
fn page_a() -> Html {
    html! {
        <>
            <Helmet>
                // The title to apply.
                <title>{"page a title"}</title>
            </Helmet>
            <div>{"This is page A."}</div>
        </>
    }
}

#[function_component(App)]
fn app() -> Html {
    html! {
        <BounceRoot>
            // A helmet bridge is required to apply helmet elements to the head element.
            // You only need 1 helmet bridge per bounce root.
            // The helmet bridge is intended to live as long as the BounceRoot.
            <HelmetBridge default_title="default title" />
            <Helmet>
                // The title to apply.
                //
                // However, as <PageA /> also renders a title element, elements rendered later
                // will have a higher priority. Hence, "page a title" will become the document
                // title.
                <title>{"app title"}</title>
            </Helmet>
            <PageA />
        </BounceRoot>
    }
}

Bounce Helmet also supports Server-side rendering.

Structs

Enums

  • An element supported by <Helmet /> with its attributes and content.

Functions

  • Creates a new Static Renderer - Static Writer pair.