dioxus/examples/flat_router.rs

80 lines
1.6 KiB
Rust
Raw Normal View History

2022-03-05 21:10:17 +00:00
use dioxus::prelude::*;
use dioxus_desktop::{tao::dpi::LogicalSize, Config, WindowBuilder};
2022-12-16 10:55:20 +00:00
use dioxus_router::prelude::*;
2022-03-04 18:08:25 +00:00
fn main() {
env_logger::init();
2024-01-16 15:40:17 +00:00
LaunchBuilder::new(Route::Home {})
.cfg(
Config::new().with_window(
WindowBuilder::new()
.with_inner_size(LogicalSize::new(600, 1000))
.with_resizable(false),
),
)
.launch()
2023-06-02 17:33:47 +00:00
}
#[derive(Routable, Clone)]
#[rustfmt::skip]
enum Route {
#[layout(Footer)]
#[route("/")]
Home {},
#[route("/games")]
Games {},
#[route("/play")]
Play {},
#[route("/settings")]
Settings {},
}
2022-12-16 10:55:20 +00:00
#[component]
fn Footer() -> Element {
2022-12-16 10:55:20 +00:00
render! {
2022-12-17 06:39:27 +00:00
div {
Outlet::<Route> {}
2022-12-16 10:55:20 +00:00
p { "----" }
2022-12-16 10:55:20 +00:00
nav {
ul {
li {
Link { to: Route::Home {}, "Home" }
}
li {
Link { to: Route::Games {}, "Games" }
}
li {
Link { to: Route::Play {}, "Play" }
}
li {
Link { to: Route::Settings {}, "Settings" }
}
2022-03-04 18:08:25 +00:00
}
}
}
2022-12-16 10:55:20 +00:00
}
}
#[component]
fn Home() -> Element {
2022-12-16 10:55:20 +00:00
render!("Home")
}
#[component]
fn Games() -> Element {
2022-12-16 10:55:20 +00:00
render!("Games")
}
#[component]
fn Play() -> Element {
2022-12-16 10:55:20 +00:00
render!("Play")
}
#[component]
fn Settings() -> Element {
2022-12-16 10:55:20 +00:00
render!("Settings")
2022-03-04 18:08:25 +00:00
}