2022-12-16 10:55:20 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2022-12-13 02:31:30 +00:00
|
|
|
use dioxus::prelude::*;
|
2022-12-16 10:55:20 +00:00
|
|
|
use dioxus_router::prelude::*;
|
2022-12-13 02:31:30 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
simple_logger::SimpleLogger::new()
|
|
|
|
.with_level(log::LevelFilter::Debug)
|
|
|
|
.with_module_level("dioxus_router", log::LevelFilter::Trace)
|
|
|
|
.with_module_level("dioxus", log::LevelFilter::Trace)
|
|
|
|
.init()
|
|
|
|
.unwrap();
|
|
|
|
dioxus_desktop::launch(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
|
|
|
"blog",
|
|
|
|
Route::empty().nested(
|
|
|
|
Segment::content(comp(BlogList)).catch_all((comp(BlogPost), PostId {})),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.fixed("oranges", comp(Oranges))
|
|
|
|
.fixed("apples", "/oranges")
|
|
|
|
});
|
|
|
|
|
|
|
|
render! {
|
|
|
|
h1 { "Your app here" }
|
|
|
|
ul {
|
|
|
|
li { Link { target: "/", "home" } }
|
|
|
|
li { Link { target: "/blog", "blog" } }
|
|
|
|
li { Link { target: "/blog/tim", "tims' blog" } }
|
|
|
|
li { Link { target: "/blog/bill", "bills' blog" } }
|
|
|
|
li { Link { target: "/blog/james", "james amazing' blog" } }
|
|
|
|
li { Link { target: "/apples", "go to apples" } }
|
2022-12-13 02:31:30 +00:00
|
|
|
}
|
2022-12-16 10:55:20 +00:00
|
|
|
Outlet { }
|
|
|
|
}
|
2022-12-13 02:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Home(cx: Scope) -> Element {
|
|
|
|
log::debug!("rendering home {:?}", cx.scope_id());
|
2022-12-16 10:55:20 +00:00
|
|
|
render! { h1 { "Home" } }
|
2022-12-13 02:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn BlogList(cx: Scope) -> Element {
|
|
|
|
log::debug!("rendering blog list {:?}", cx.scope_id());
|
2022-12-16 10:55:20 +00:00
|
|
|
render! { div { "Blog List" } }
|
2022-12-13 02:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 10:55:20 +00:00
|
|
|
struct PostId;
|
2022-12-13 02:31:30 +00:00
|
|
|
fn BlogPost(cx: Scope) -> Element {
|
2022-12-16 10:55:20 +00:00
|
|
|
let Some(id) = use_route(cx)?.parameter::<PostId>() else {
|
|
|
|
return render!(div { "No blog post id" });
|
2022-12-13 02:31:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
log::debug!("rendering blog post {}", id);
|
|
|
|
|
2022-12-16 10:55:20 +00:00
|
|
|
render! {
|
2022-12-13 22:44:47 +00:00
|
|
|
div {
|
|
|
|
h3 { "blog post: {id:?}" }
|
2022-12-16 10:55:20 +00:00
|
|
|
Link { target: "/blog/", "back to blog list" }
|
2022-12-13 22:44:47 +00:00
|
|
|
}
|
2022-12-16 10:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Oranges(cx: Scope) -> Element {
|
|
|
|
render!("Oranges are not apples!")
|
2022-12-13 02:31:30 +00:00
|
|
|
}
|