Files
dioxus/packages/fullstack/examples/static-hydrated/src/main.rs
T

81 lines
1.9 KiB
Rust

//! Run with:
//!
//! ```sh
//! dx build --features web --release
//! cargo run --features server
//! ```
#![allow(unused)]
use dioxus::prelude::*;
use dioxus_fullstack::{launch, prelude::*};
use serde::{Deserialize, Serialize};
// Generate all routes and output them to the docs path
#[cfg(feature = "server")]
#[tokio::main]
async fn main() {
pre_cache_static_routes_with_props(
&ServeConfig::new_with_router(
dioxus_fullstack::router::FullstackRouterConfig::<Route>::default(),
)
.assets_path("docs")
.incremental(IncrementalRendererConfig::default().static_dir("docs"))
.build(),
)
.await
.unwrap();
}
// Hydrate the page
#[cfg(all(feature = "web", not(feature = "server")))]
fn main() {
dioxus_web::launch_with_props(
dioxus_fullstack::router::RouteWithCfg::<Route>,
dioxus_fullstack::prelude::get_root_props_from_document()
.expect("Failed to get root props from document"),
dioxus_web::Config::default().hydrate(true),
);
}
#[derive(Clone, Routable, Debug, PartialEq, Serialize, Deserialize)]
enum Route {
#[route("/")]
Home {},
#[route("/blog")]
Blog,
}
#[component]
fn Blog() -> Element {
rsx! {
Link { to: Route::Home {}, "Go to counter" }
table {
tbody {
for _ in 0..100 {
tr {
for _ in 0..100 {
td { "hello world!" }
}
}
}
}
}
}
}
#[component]
fn Home() -> Element {
let mut count = use_signal(|| 0);
let text = use_signal(|| "...".to_string());
rsx! {
Link { to: Route::Blog {}, "Go to blog" }
div {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}
}