dioxus/examples/flat_router.rs

79 lines
1.5 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();
let cfg = Config::new().with_window(
WindowBuilder::new()
.with_inner_size(LogicalSize::new(600, 1000))
.with_resizable(false),
);
dioxus_desktop::launch_cfg(App, cfg)
2022-03-04 18:08:25 +00:00
}
#[component]
fn App(cx: Scope) -> Element {
2023-06-02 17:33:47 +00:00
render! {
2023-07-26 01:14:48 +00:00
Router::<Route> {}
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]
2023-06-02 17:33:47 +00:00
fn Footer(cx: Scope) -> Element {
2022-12-16 10:55:20 +00:00
render! {
2022-12-17 06:39:27 +00:00
div {
2023-07-26 01:14:48 +00:00
Outlet::<Route> { }
2022-12-16 10:55:20 +00:00
p {
"----"
}
2022-12-16 10:55:20 +00:00
nav {
ul {
2023-07-24 18:57:56 +00:00
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]
2022-12-16 10:55:20 +00:00
fn Home(cx: Scope) -> Element {
render!("Home")
}
#[component]
2022-12-16 10:55:20 +00:00
fn Games(cx: Scope) -> Element {
render!("Games")
}
#[component]
2022-12-16 10:55:20 +00:00
fn Play(cx: Scope) -> Element {
render!("Play")
}
#[component]
2022-12-16 10:55:20 +00:00
fn Settings(cx: Scope) -> Element {
render!("Settings")
2022-03-04 18:08:25 +00:00
}