main.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //! Static generation works out of the box with the router. Just add a router anywhere in your app and it will generate any static routes for you!
  2. #![allow(unused)]
  3. use dioxus::prelude::*;
  4. // Generate all routes and output them to the static path
  5. fn main() {
  6. launch(|| {
  7. rsx! {
  8. Router::<Route> {}
  9. }
  10. });
  11. }
  12. #[derive(Clone, Routable, Debug, PartialEq)]
  13. enum Route {
  14. #[route("/")]
  15. Home {},
  16. #[route("/blog")]
  17. Blog,
  18. }
  19. #[component]
  20. fn Blog() -> Element {
  21. rsx! {
  22. Link { to: Route::Home {}, "Go to counter" }
  23. table {
  24. tbody {
  25. for _ in 0..100 {
  26. tr {
  27. for _ in 0..100 {
  28. td { "hello!" }
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. #[component]
  37. fn Home() -> Element {
  38. let mut count = use_signal(|| 0);
  39. rsx! {
  40. Link { to: Route::Blog {}, "Go to blog" }
  41. div {
  42. h1 { "High-Five counter: {count}" }
  43. button { onclick: move |_| count += 1, "Up high!" }
  44. button { onclick: move |_| count -= 1, "Down low!" }
  45. }
  46. }
  47. }