simple.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. &|| Segment::content(comp(RootIndex)).fixed("apple", comp(Apple)),
  16. );
  17. render! {
  18. h1 { "Simple Example App" }
  19. nav {
  20. Link {
  21. target: named::<RootIndex>(),
  22. "Go to root"
  23. }
  24. }
  25. Outlet { }
  26. }
  27. }
  28. fn RootIndex(cx: Scope) -> Element {
  29. render! {
  30. h2 { "Root Index" }
  31. ul {
  32. li {
  33. Link {
  34. target: "/apple",
  35. "Read about apples…"
  36. }
  37. }
  38. }
  39. }
  40. }
  41. fn Apple(cx: Scope) -> Element {
  42. render! {
  43. h2 { "Apple" }
  44. p {
  45. "An apple is a tasty fruit. It grows on trees and many varieties are either red or "
  46. "green."
  47. }
  48. }
  49. }