docs: update documentation for #[lazy] and #[lazy_route]

This commit is contained in:
Greg Johnston
2025-07-21 08:53:38 -04:00
parent 14884bc8ac
commit fbe7cdc482
3 changed files with 63 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ quote = { workspace = true, default-features = true }
syn = { features = ["full"], workspace = true, default-features = true }
[dev-dependencies]
leptos = { path = "../leptos" }
leptos_router = { path = "../router" }
leptos_macro = { path = "../leptos_macro" }

View File

@@ -198,6 +198,37 @@ impl ToTokens for Segments {
/// add a [`lazy`] annotation to the `view` method, which will cause the code for the view
/// to lazy-load concurrently with the `data` being loaded for the route.
///
/// ```rust
/// use leptos::prelude::*;
/// use leptos_router::{lazy_route, LazyRoute};
///
/// // the route definition
/// #[derive(Debug)]
/// struct BlogListingRoute {
/// titles: Resource<Vec<String>>
/// }
///
/// #[lazy_route]
/// impl LazyRoute for BlogListingRoute {
/// fn data() -> Self {
/// Self {
/// titles: Resource::new(|| (), |_| async {
/// vec![/* todo: load blog posts */]
/// })
/// }
/// }
///
/// // this function will be lazy-loaded, concurrently with data()
/// fn view(this: Self) -> AnyView {
/// let BlogListingRoute { titles } = this;
///
/// // ... now you can use the `posts` resource with Suspense, etc.,
/// // and return AnyView by calling .into_any() on a view
/// # ().into_any()
/// }
/// }
/// ```
///
/// [`impl LazyRoute`]: https://docs.rs/leptos_router/latest/leptos_router/trait.LazyRoute.html
/// [`lazy`]: https://docs.rs/leptos_macro/latest/leptos_macro/macro.lazy.html
#[proc_macro_attribute]