dioxus/examples/flat_router.rs

73 lines
1.2 KiB
Rust
Raw Normal View History

2022-03-05 21:10:17 +00:00
use dioxus::prelude::*;
2022-03-04 18:08:25 +00:00
fn main() {
2024-01-20 08:11:55 +00:00
launch(|| {
rsx! {
Router::<Route> {}
}
})
2023-06-02 17:33:47 +00:00
}
#[derive(Routable, Clone)]
#[rustfmt::skip]
enum Route {
#[layout(Footer)]
#[route("/")]
Home {},
2024-01-20 08:11:55 +00:00
2023-06-02 17:33:47 +00:00
#[route("/games")]
Games {},
2024-01-20 08:11:55 +00:00
2023-06-02 17:33:47 +00:00
#[route("/play")]
Play {},
2024-01-20 08:11:55 +00:00
2023-06-02 17:33:47 +00:00
#[route("/settings")]
Settings {},
}
2022-12-16 10:55:20 +00:00
#[component]
fn Footer() -> Element {
2024-01-16 19:18:46 +00:00
rsx! {
2024-01-20 08:11:55 +00:00
Outlet::<Route> {}
p { "----" }
nav {
style { {STYLE} }
Link { to: Route::Home {}, class: "nav-btn", "Home" }
Link { to: Route::Games {}, class: "nav-btn", "Games" }
Link { to: Route::Play {}, class: "nav-btn", "Play" }
Link { to: Route::Settings {}, class: "nav-btn", "Settings" }
2022-03-04 18:08:25 +00:00
}
2022-12-16 10:55:20 +00:00
}
}
#[component]
fn Home() -> Element {
2024-01-16 19:18:46 +00:00
rsx!("Home")
2022-12-16 10:55:20 +00:00
}
#[component]
fn Games() -> Element {
2024-01-16 19:18:46 +00:00
rsx!("Games")
2022-12-16 10:55:20 +00:00
}
#[component]
fn Play() -> Element {
2024-01-16 19:18:46 +00:00
rsx!("Play")
2022-12-16 10:55:20 +00:00
}
#[component]
fn Settings() -> Element {
2024-01-16 19:18:46 +00:00
rsx!("Settings")
2022-03-04 18:08:25 +00:00
}
2024-01-20 08:11:55 +00:00
const STYLE: &str = r#"
nav {
display: flex;
justify-content: space-around;
}
.nav-btn {
text-decoration: none;
color: black;
}
"#;