dioxus/examples/flat_router.rs

80 lines
1.5 KiB
Rust
Raw Normal View History

2022-12-16 11:55:20 +01:00
#![allow(non_snake_case)]
2022-03-05 16:10:17 -05:00
use dioxus::prelude::*;
use dioxus_desktop::{tao::dpi::LogicalSize, Config, WindowBuilder};
2022-12-16 11:55:20 +01:00
use dioxus_router::prelude::*;
2022-03-04 13:08:25 -05: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 13:08:25 -05:00
}
fn app(cx: Scope) -> Element {
2023-06-02 12:33:47 -05:00
render! {
Router {}
}
}
#[derive(Routable, Clone)]
#[rustfmt::skip]
enum Route {
#[layout(Footer)]
#[route("/")]
Home {},
#[route("/games")]
Games {},
#[route("/play")]
Play {},
#[route("/settings")]
Settings {},
}
2022-12-16 11:55:20 +01:00
2023-06-02 12:33:47 -05:00
#[inline_props]
fn Footer(cx: Scope) -> Element {
2022-12-16 11:55:20 +01:00
render! {
2022-12-16 22:39:27 -08:00
div {
Outlet { }
2022-12-16 11:55:20 +01:00
p {
"----"
}
2022-12-16 11:55:20 +01:00
nav {
ul {
2023-06-02 12:33:47 -05:00
li { Link { target: Route::Home {}, "Home" } }
li { Link { target: Route::Games {}, "Games" } }
li { Link { target: Route::Play {}, "Play" } }
li { Link { target: Route::Settings {}, "Settings" } }
2022-03-04 13:08:25 -05:00
}
}
}
2022-12-16 11:55:20 +01:00
}
}
2023-06-02 12:33:47 -05:00
#[inline_props]
2022-12-16 11:55:20 +01:00
fn Home(cx: Scope) -> Element {
render!("Home")
}
2023-06-02 12:33:47 -05:00
#[inline_props]
2022-12-16 11:55:20 +01:00
fn Games(cx: Scope) -> Element {
render!("Games")
}
2023-06-02 12:33:47 -05:00
#[inline_props]
2022-12-16 11:55:20 +01:00
fn Play(cx: Scope) -> Element {
render!("Play")
}
2023-06-02 12:33:47 -05:00
#[inline_props]
2022-12-16 11:55:20 +01:00
fn Settings(cx: Scope) -> Element {
render!("Settings")
2022-03-04 13:08:25 -05:00
}