1
0

flat_router.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use dioxus_desktop::{tao::dpi::LogicalSize, Config, WindowBuilder};
  4. use dioxus_router::prelude::*;
  5. fn main() {
  6. env_logger::init();
  7. let cfg = Config::new().with_window(
  8. WindowBuilder::new()
  9. .with_inner_size(LogicalSize::new(600, 1000))
  10. .with_resizable(false),
  11. );
  12. dioxus_desktop::launch_cfg(app, cfg)
  13. }
  14. fn app(cx: Scope) -> Element {
  15. render! {
  16. Router {}
  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. #[inline_props]
  33. fn Footer(cx: Scope) -> Element {
  34. render! {
  35. div {
  36. Outlet { }
  37. p {
  38. "----"
  39. }
  40. nav {
  41. ul {
  42. li { Link { target: Route::Home {}, "Home" } }
  43. li { Link { target: Route::Games {}, "Games" } }
  44. li { Link { target: Route::Play {}, "Play" } }
  45. li { Link { target: Route::Settings {}, "Settings" } }
  46. }
  47. }
  48. }
  49. }
  50. }
  51. #[inline_props]
  52. fn Home(cx: Scope) -> Element {
  53. render!("Home")
  54. }
  55. #[inline_props]
  56. fn Games(cx: Scope) -> Element {
  57. render!("Games")
  58. }
  59. #[inline_props]
  60. fn Play(cx: Scope) -> Element {
  61. render!("Play")
  62. }
  63. #[inline_props]
  64. fn Settings(cx: Scope) -> Element {
  65. render!("Settings")
  66. }