link.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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(cx, &RouterConfiguration::default, &|| {
  9. Segment::content(comp(Home)).fixed("settings", comp(Settings))
  10. });
  11. cx.render(rsx! (
  12. div {
  13. p {
  14. a { href: "http://dioxuslabs.com/", "Default link - links outside of your app" }
  15. }
  16. p {
  17. a {
  18. href: "http://dioxuslabs.com/",
  19. prevent_default: "onclick",
  20. onclick: |_| println!("Hello Dioxus"),
  21. "Custom event link - links inside of your app",
  22. }
  23. }
  24. }
  25. div {
  26. Outlet { }
  27. p { "----"}
  28. ul {
  29. Link { target: "/", li { "Router link to home" } },
  30. Link { target: "/settings", li { "Router link to settings" } },
  31. }
  32. }
  33. ))
  34. }
  35. fn Home(cx: Scope) -> Element {
  36. render!(h1 { "Home" })
  37. }
  38. fn Settings(cx: Scope) -> Element {
  39. render!(h1 { "Settings" })
  40. }