1
0

main.rs 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #![allow(non_snake_case)]
  2. use components::home::Home;
  3. use components::loading::ChildrenOrLoading;
  4. use dioxus::prelude::*;
  5. mod components {
  6. pub mod error;
  7. pub mod home;
  8. pub mod loading;
  9. pub mod nav;
  10. pub mod product_item;
  11. pub mod product_page;
  12. }
  13. mod api;
  14. fn main() {
  15. dioxus::launch(|| {
  16. rsx! {
  17. document::Link {
  18. rel: "stylesheet",
  19. href: asset!("/public/tailwind.css")
  20. }
  21. ChildrenOrLoading {
  22. Router::<Route> {}
  23. }
  24. }
  25. });
  26. }
  27. #[derive(Clone, Routable, Debug, PartialEq)]
  28. enum Route {
  29. #[route("/")]
  30. Home {},
  31. #[route("/details/:product_id")]
  32. Details { product_id: usize },
  33. }
  34. #[component]
  35. /// Render a more sophisticated page with ssr
  36. fn Details(product_id: usize) -> Element {
  37. rsx! {
  38. div {
  39. components::nav::nav {}
  40. components::product_page::product_page {
  41. product_id
  42. }
  43. }
  44. }
  45. }