first_route.rs 787 B

123456789101112131415161718192021222324252627282930313233343536
  1. // ANCHOR: router
  2. #![allow(non_snake_case)]
  3. use dioxus::prelude::*;
  4. use dioxus_router::prelude::*;
  5. /// An enum of all of the possible routes in the app.
  6. #[derive(Routable, Clone)]
  7. enum Route {
  8. // The home page is at the / route
  9. #[route("/")]
  10. // If the name of the component and variant are the same you can omit the component and props name
  11. // If they are different you can specify them like this:
  12. // #[route("/", ComponentName, PropsName)]
  13. Home {},
  14. }
  15. // ANCHOR_END: router
  16. // ANCHOR: app
  17. #[inline_props]
  18. fn App(cx: Scope) -> Element {
  19. render! {
  20. Router {}
  21. }
  22. }
  23. // ANCHOR_END: app
  24. // ANCHOR: home
  25. #[inline_props]
  26. fn Home(cx: Scope) -> Element {
  27. render! {
  28. h1 { "Welcome to the Dioxus Blog!" }
  29. }
  30. }
  31. // ANCHOR_END: home
  32. fn main() {}