Trait dioxus_fullstack::prelude::DioxusRouterExt
source · pub trait DioxusRouterExt<S> {
// Required methods
fn register_server_functions_with_context(
self,
context_providers: Arc<Vec<Box<dyn Fn() -> Box<dyn Any + Send + Sync + 'static> + Send + Sync + 'static>>>,
) -> Self;
fn serve_static_assets(self) -> Self
where Self: Sized;
fn serve_dioxus_application(
self,
cfg: impl Into<ServeConfig>,
app: fn() -> Element,
) -> Self
where Self: Sized;
// Provided method
fn register_server_functions(self) -> Self
where Self: Sized { ... }
}Available on crate feature
axum only.Expand description
A extension trait with utilities for integrating Dioxus with your Axum router.
Required Methods§
sourcefn register_server_functions_with_context(
self,
context_providers: Arc<Vec<Box<dyn Fn() -> Box<dyn Any + Send + Sync + 'static> + Send + Sync + 'static>>>,
) -> Self
fn register_server_functions_with_context( self, context_providers: Arc<Vec<Box<dyn Fn() -> Box<dyn Any + Send + Sync + 'static> + Send + Sync + 'static>>>, ) -> Self
Registers server functions with some additional context to insert into the DioxusServerContext for that handler.
§Example
#[tokio::main]
async fn main() {
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
let router = axum::Router::new()
// Register server functions routes with the default handler
.register_server_functions_with_context(Arc::new(vec![Box::new(|| Box::new(1234567890u32))]))
.into_make_service();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, router).await.unwrap();
}sourcefn serve_static_assets(self) -> Selfwhere
Self: Sized,
fn serve_static_assets(self) -> Selfwhere
Self: Sized,
Serves the static WASM for your Dioxus application (except the generated index.html).
§Example
#[tokio::main]
async fn main() {
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
let router = axum::Router::new()
// Server side render the application, serve static assets, and register server functions
.serve_static_assets()
// Server render the application
// ...
.into_make_service();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, router).await.unwrap();
}sourcefn serve_dioxus_application(
self,
cfg: impl Into<ServeConfig>,
app: fn() -> Element,
) -> Selfwhere
Self: Sized,
fn serve_dioxus_application(
self,
cfg: impl Into<ServeConfig>,
app: fn() -> Element,
) -> Selfwhere
Self: Sized,
Serves the Dioxus application. This will serve a complete server side rendered application. This will serve static assets, server render the application, register server functions, and integrate with hot reloading.
§Example
#[tokio::main]
async fn main() {
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
let router = axum::Router::new()
// Server side render the application, serve static assets, and register server functions
.serve_dioxus_application(ServeConfig::default(), app)
.into_make_service();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, router).await.unwrap();
}
fn app() -> Element {
rsx! { "Hello World" }
}Provided Methods§
sourcefn register_server_functions(self) -> Selfwhere
Self: Sized,
fn register_server_functions(self) -> Selfwhere
Self: Sized,
Registers server functions with the default handler. This handler function will pass an empty DioxusServerContext to your server functions.
§Example
#[tokio::main]
async fn main() {
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
let router = axum::Router::new()
// Register server functions routes with the default handler
.register_server_functions()
.into_make_service();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, router).await.unwrap();
}Object Safety§
This trait is not object safe.