flat_router.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. use dioxus::prelude::*;
  2. fn main() {
  3. launch(|| {
  4. rsx! {
  5. Router::<Route> {}
  6. }
  7. })
  8. }
  9. #[derive(Routable, Clone)]
  10. #[rustfmt::skip]
  11. enum Route {
  12. #[layout(Footer)]
  13. #[route("/")]
  14. Home {},
  15. #[route("/games")]
  16. Games {},
  17. #[route("/play")]
  18. Play {},
  19. #[route("/settings")]
  20. Settings {},
  21. }
  22. #[component]
  23. fn Footer() -> Element {
  24. rsx! {
  25. Outlet::<Route> {}
  26. p { "----" }
  27. nav {
  28. style { {STYLE} }
  29. Link { to: Route::Home {}, class: "nav-btn", "Home" }
  30. Link { to: Route::Games {}, class: "nav-btn", "Games" }
  31. Link { to: Route::Play {}, class: "nav-btn", "Play" }
  32. Link { to: Route::Settings {}, class: "nav-btn", "Settings" }
  33. }
  34. }
  35. }
  36. #[component]
  37. fn Home() -> Element {
  38. rsx!("Home")
  39. }
  40. #[component]
  41. fn Games() -> Element {
  42. rsx!("Games")
  43. }
  44. #[component]
  45. fn Play() -> Element {
  46. rsx!("Play")
  47. }
  48. #[component]
  49. fn Settings() -> Element {
  50. rsx!("Settings")
  51. }
  52. const STYLE: &str = r#"
  53. nav {
  54. display: flex;
  55. justify-content: space-around;
  56. }
  57. .nav-btn {
  58. text-decoration: none;
  59. color: black;
  60. }
  61. "#;