pub struct WireApp { /* private fields */ }Implementations§
Source§impl WireApp
impl WireApp
pub fn new() -> Self
Sourcepub fn layout<F>(self, name: &str, f: F) -> Self
pub fn layout<F>(self, name: &str, f: F) -> Self
Register a named layout function.
The name "default" is special — it’s used when no #[layout] attribute
is set on the component and no per-route override is given.
WireApp::new()
.layout("default", |ctx| { ... })
.layout("auth", auth_layout)
.layout("admin", admin_layout)Sourcepub fn layout_str(self, name: &str, template: &str) -> Self
pub fn layout_str(self, name: &str, template: &str) -> Self
Register a layout from an HTML template string.
The template supports these placeholders:
@wireBody— the rendered component HTML@wireScripts— the wire JS runtime<script>tags@wireStyles— the wire CSS<style>tag@wireTitle— the component’s wire name
WireApp::new()
.layout_str("auth", include_str!("layouts/auth.html"))Sourcepub fn layout_file(self, name: &str, path: &str) -> Self
pub fn layout_file(self, name: &str, path: &str) -> Self
Sourcepub fn state<T: Clone + Send + Sync + 'static>(self, value: T) -> Self
pub fn state<T: Clone + Send + Sync + 'static>(self, value: T) -> Self
Add shared application state accessible via ctx.state::<T>() in components.
let app = WireApp::new()
.state(db_pool)
.state(redis_client)
.wire("/posts/{postId}", "post-view")
.into_router();Sourcepub fn wire(self, path: &str, component_name: &str) -> Self
pub fn wire(self, path: &str, component_name: &str) -> Self
Register a wire component route. Layout is resolved from the component’s
#[layout("name")] attribute, falling back to "default".
Sourcepub fn wire_with<F>(
self,
path: &str,
component_name: &str,
layout_fn: F,
) -> Self
pub fn wire_with<F>( self, path: &str, component_name: &str, layout_fn: F, ) -> Self
Register a wire component route with an explicit per-route layout function.
This overrides any #[layout] attribute on the component.
Sourcepub fn layer<L>(self, layer: L) -> Self
pub fn layer<L>(self, layer: L) -> Self
Apply a Tower layer/middleware to wire page routes.
Like axum::Router::layer, this applies to the routes that currently
exist in the builder. Routes registered later are unaffected.
/_wire/update is intentionally not layered by Axum. Instead, during
an AJAX update, axum-wire replays the layers associated with the
original mounted route (tracked via __wire_ctx in the snapshot).
To scope middleware to a subset of routes, use group(...).
use tower_http::cors::CorsLayer;
use tower_http::compression::CompressionLayer;
WireApp::new()
.wire("/", "counter")
.layer(CorsLayer::permissive())
.layer(CompressionLayer::new())
.into_router();Sourcepub fn group<F>(self, f: F) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn group<F>(self, f: F) -> Selfwhere
F: FnOnce(Self) -> Self,
Build a scoped set of wire routes and layers, then merge them back.
This is useful when you want Axum-like layering on just a subset of routes without affecting the rest of the app.
WireApp::new()
.wire("/", "home")
.group(|app| {
app.wire("/admin", "admin-dashboard")
.wire("/admin/posts", "admin-posts")
.layer(auth_layer)
})
.wire("/about", "about")