Function leptos_actix::render_app_to_stream_in_order

source ·
pub fn render_app_to_stream_in_order<IV>(
    options: LeptosOptions,
    app_fn: impl Fn() -> IV + Clone + 'static,
    method: Method,
) -> Route
where IV: IntoView,
Expand description

Returns an Actix struct@Route that listens for a GET request and tries to route it using leptos_router, serving an in-order HTML stream of your application. This stream will pause at each <Suspense/> node and wait for it to resolve before sending down its HTML. The app will become interactive once it has fully loaded.

The provides a MetaContext and a RouterIntegrationContext to app’s context before rendering it, and includes any meta tags injected using leptos_meta.

The HTML stream is rendered using render_to_stream_in_order, and includes everything described in the documentation for that function.

This can then be set up at an appropriate route in your application:

use actix_web::{App, HttpServer};
use leptos::*;
use leptos_router::Method;
use std::{env, net::SocketAddr};

#[component]
fn MyApp() -> impl IntoView {
    view! { <main>"Hello, world!"</main> }
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
    let addr = conf.leptos_options.site_addr.clone();
    HttpServer::new(move || {
        let leptos_options = &conf.leptos_options;

        App::new()
            // {tail:.*} passes the remainder of the URL as the route
            // the actual routing will be handled by `leptos_router`
            .route(
                "/{tail:.*}",
                leptos_actix::render_app_to_stream_in_order(
                    leptos_options.to_owned(),
                    || view! { <MyApp/> },
                    Method::Get,
                ),
            )
    })
    .bind(&addr)?
    .run()
    .await
}

§Provided Context Types

This function always provides context values including the following types: