link.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. cx.render(rsx! (
  9. div {
  10. p {
  11. a { href: "http://dioxuslabs.com/", "Default link - links outside of your app" }
  12. }
  13. p {
  14. a {
  15. href: "http://dioxuslabs.com/",
  16. prevent_default: "onclick",
  17. onclick: |_| println!("Hello Dioxus"),
  18. "Custom event link - links inside of your app",
  19. }
  20. }
  21. }
  22. div {
  23. Router::<Route> {}
  24. }
  25. ))
  26. }
  27. #[derive(Routable, Clone)]
  28. #[rustfmt::skip]
  29. enum Route {
  30. #[layout(Header)]
  31. #[route("/")]
  32. Home {},
  33. #[route("/settings")]
  34. Settings {},
  35. }
  36. #[inline_props]
  37. fn Header(cx: Scope) -> Element {
  38. render! {
  39. h1 { "Your app here" }
  40. ul {
  41. li { Link { to: Route::Home {}, "home" } }
  42. li { Link { to: Route::Settings {}, "settings" } }
  43. }
  44. Outlet::<Route> {}
  45. }
  46. }
  47. #[inline_props]
  48. fn Home(cx: Scope) -> Element {
  49. render!(h1 { "Home" })
  50. }
  51. #[inline_props]
  52. fn Settings(cx: Scope) -> Element {
  53. render!(h1 { "Settings" })
  54. }