1
0

flat_router.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. use dioxus::prelude::*;
  2. use dioxus_desktop::{tao::dpi::LogicalSize, Config, WindowBuilder};
  3. use dioxus_router::prelude::*;
  4. fn main() {
  5. env_logger::init();
  6. let cfg = Config::new().with_window(
  7. WindowBuilder::new()
  8. .with_inner_size(LogicalSize::new(600, 1000))
  9. .with_resizable(false),
  10. );
  11. dioxus_desktop::launch_cfg(App, cfg)
  12. }
  13. #[component]
  14. fn App(cx: Scope) -> Element {
  15. render! {
  16. Router::<Route> {}
  17. }
  18. }
  19. #[derive(Routable, Clone)]
  20. #[rustfmt::skip]
  21. enum Route {
  22. #[layout(Footer)]
  23. #[route("/")]
  24. Home {},
  25. #[route("/games")]
  26. Games {},
  27. #[route("/play")]
  28. Play {},
  29. #[route("/settings")]
  30. Settings {},
  31. }
  32. #[component]
  33. fn Footer(cx: Scope) -> Element {
  34. render! {
  35. div {
  36. Outlet::<Route> { }
  37. p {
  38. "----"
  39. }
  40. nav {
  41. ul {
  42. li { Link { to: Route::Home {}, "Home" } }
  43. li { Link { to: Route::Games {}, "Games" } }
  44. li { Link { to: Route::Play {}, "Play" } }
  45. li { Link { to: Route::Settings {}, "Settings" } }
  46. }
  47. }
  48. }
  49. }
  50. }
  51. #[component]
  52. fn Home(cx: Scope) -> Element {
  53. render!("Home")
  54. }
  55. #[component]
  56. fn Games(cx: Scope) -> Element {
  57. render!("Games")
  58. }
  59. #[component]
  60. fn Play(cx: Scope) -> Element {
  61. render!("Play")
  62. }
  63. #[component]
  64. fn Settings(cx: Scope) -> Element {
  65. render!("Settings")
  66. }