#[shard]Expand description
Transforms a function into a shard component that can be navigated to via the routing system and (optionally) provided with a lazily‑initialized per‑shard state.
§Features
- Generates a
StructNameDestination(UpperCamelCase +Destination) implementingtessera_ui::router::RouterDestination - Optional state injection via
#[shard(state = T)], whereT:- Must implement
Default + Send + Sync + 'static - Is constructed (or reused) and exposed as local variable
statewith typetessera_shard::ShardState<T>
- Must implement
- Produces a stable shard ID:
module_path!()::function_name
§Lifecycle
Controlled by the lifecycle shard attribute argument.
- Default:
Shard– state is removed when the destination ispop()‑ed - Override:
#[shard(lifecycle = scope)]to persist for the lifetime of the current router controller hosted byshard_home
Route-scoped state is removed on route pop/clear. Scope-scoped state is
removed when the hosting shard_home is dropped.
§Parameter Transformation
- Function parameters are treated as explicit destination props.
- When
state = Tis configured, shard state is injected as local variablestateand does not appear in the function signature.
§Generated Destination (Conceptual)
ⓘ
struct ProfilePageDestination { /* non-state params as public fields */ }
impl RouterDestination for ProfilePageDestination {
fn exec_component(&self) { profile_page(/* fields */); }
fn shard_id(&self) -> &'static str { "<module>::profile_page" }
}§Limitations
- Do not manually implement
RouterDestinationfor these pages; rely on generation
§See Also
- Routing helpers:
tessera_ui::router::{shard_home, router_outlet} - Router controller internals:
tessera_ui::router::RouterController
§Errors
Emits a compile error if unsupported lifecycle is provided, or if
lifecycle is used without state.