simple.rs 1.6 KB

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