flat_router.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. use_router(cx, &RouterConfiguration::default, &|| {
  16. Segment::content(comp(Home))
  17. .fixed("games", comp(Games))
  18. .fixed("play", comp(Play))
  19. .fixed("settings", comp(Settings))
  20. });
  21. render! {
  22. div {
  23. Outlet { }
  24. p {
  25. "----"
  26. }
  27. nav {
  28. ul {
  29. li { Link { target: "/", "Home" } }
  30. li { Link { target: "/games", "Games" } }
  31. li { Link { target: "/play", "Play" } }
  32. li { Link { target: "/settings", "Settings" } }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. fn Home(cx: Scope) -> Element {
  39. render!("Home")
  40. }
  41. fn Games(cx: Scope) -> Element {
  42. render!("Games")
  43. }
  44. fn Play(cx: Scope) -> Element {
  45. render!("Play")
  46. }
  47. fn Settings(cx: Scope) -> Element {
  48. render!("Settings")
  49. }