simple.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use dioxus_router::prelude::*;
  4. use dioxus_router_core::history::MemoryHistory;
  5. fn main() {
  6. dioxus_desktop::launch(App);
  7. }
  8. fn App(cx: Scope) -> Element {
  9. use_router(
  10. &cx,
  11. &|| RouterConfiguration {
  12. // history: Box::new(MemoryHistory::with_initial_path("/apple").unwrap()),
  13. ..Default::default()
  14. },
  15. &|| {
  16. Segment::content(comp(Home))
  17. .fixed("apple", comp(Apple))
  18. .fixed("potato", Route::content(comp(Potato)).name::<PotatoName>())
  19. .fixed("earth_apple", named::<PotatoName>())
  20. },
  21. );
  22. render! {
  23. h1 { "Simple Example App" }
  24. Outlet { }
  25. Link {
  26. target: named::<RootIndex>(),
  27. "Go to root"
  28. }
  29. }
  30. }
  31. fn Home(cx: Scope) -> Element {
  32. render! {
  33. h2 { "Root Index" }
  34. ul {
  35. li { Link {
  36. target: "/apple",
  37. "Read about apples…"
  38. } }
  39. li { Link {
  40. target: named::<PotatoName>(),
  41. "Read about potatoes…"
  42. } }
  43. li { Link {
  44. target: "/earth_apple",
  45. "Read about earth apples (literal translation of a german word for potato)…"
  46. } }
  47. }
  48. }
  49. }
  50. fn Apple(cx: Scope) -> Element {
  51. render! {
  52. h2 { "Apple" }
  53. p {
  54. "An apple is a tasty fruit. It grows on trees and many varieties are either red or "
  55. "green."
  56. }
  57. }
  58. }
  59. struct PotatoName;
  60. fn Potato(cx: Scope) -> Element {
  61. render! {
  62. h2 { "Potato" }
  63. p { "The potato grows underground. There are many recipes involving potatoes." }
  64. }
  65. }