dioxus/examples/flat_router.rs

62 lines
1.3 KiB
Rust
Raw Normal View History

2022-12-16 10:55:20 +00:00
#![allow(non_snake_case)]
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
}
fn app(cx: Scope) -> Element {
2023-04-12 18:19:01 +00:00
use_router(cx, &RouterConfiguration::default, &|| {
2022-12-16 10:55:20 +00:00
Segment::content(comp(Home))
.fixed("games", comp(Games))
.fixed("play", comp(Play))
.fixed("settings", comp(Settings))
});
render! {
2022-12-17 06:39:27 +00:00
div {
Outlet { }
2022-12-16 10:55:20 +00:00
p {
"----"
}
2022-12-16 10:55:20 +00:00
nav {
ul {
li { Link { target: "/", "Home" } }
li { Link { target: "/games", "Games" } }
li { Link { target: "/play", "Play" } }
li { Link { target: "/settings", "Settings" } }
2022-03-04 18:08:25 +00:00
}
}
}
2022-12-16 10:55:20 +00:00
}
}
fn Home(cx: Scope) -> Element {
render!("Home")
}
fn Games(cx: Scope) -> Element {
render!("Games")
}
fn Play(cx: Scope) -> Element {
render!("Play")
}
fn Settings(cx: Scope) -> Element {
render!("Settings")
2022-03-04 18:08:25 +00:00
}