pub async fn render_handler(
__arg0: State<RenderHandleState>,
request: Request<Body>,
) -> impl IntoResponse
Available on crate feature
axum
only.Expand description
SSR renderer handler for Axum with added context injection.
ยงExample
#![allow(non_snake_case)]
use std::sync::{Arc, Mutex};
use axum::routing::get;
use dioxus::prelude::*;
fn app() -> Element {
rsx! {
"hello!"
}
}
#[tokio::main]
async fn main() {
let addr = dioxus::cli_config::fullstack_address_or_localhost();
let router = axum::Router::new()
// Register server functions, etc.
// Note you can use `register_server_functions_with_context`
// to inject the context into server functions running outside
// of an SSR render context.
.fallback(get(render_handler)
.with_state(RenderHandleState::new(ServeConfig::new().unwrap(), app))
)
.into_make_service();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, router).await.unwrap();
}