2022-02-11 02:00:15 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2021-11-19 05:49:04 +00:00
|
|
|
use dioxus_core::prelude::*;
|
|
|
|
use dioxus_core_macro::*;
|
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
use dioxus_router::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
console_error_panic_hook::set_once();
|
2021-11-22 20:22:42 +00:00
|
|
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
2022-03-02 22:57:57 +00:00
|
|
|
dioxus_web::launch(app);
|
2021-11-19 05:49:04 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 22:57:57 +00:00
|
|
|
fn app(cx: Scope) -> Element {
|
2022-01-05 05:27:22 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
Router {
|
2022-03-02 22:57:57 +00:00
|
|
|
h1 { "Your app here" }
|
|
|
|
ul {
|
|
|
|
Link { to: "/", li { "home" }}
|
|
|
|
Link { to: "/blog", li { "blog" }}
|
|
|
|
Link { to: "/blog/tim", li { "tims' blog" }}
|
|
|
|
Link { to: "/blog/bill", li { "bills' blog" }}
|
2022-01-05 05:27:22 +00:00
|
|
|
}
|
2022-03-02 22:57:57 +00:00
|
|
|
Route { to: "/", Home {} }
|
|
|
|
Route { to: "/blog/", BlogList {} }
|
|
|
|
Route { to: "/blog/:id/", BlogPost {} }
|
2021-12-29 04:20:01 +00:00
|
|
|
}
|
2022-01-05 05:27:22 +00:00
|
|
|
})
|
2022-03-02 22:57:57 +00:00
|
|
|
}
|
2021-11-19 05:49:04 +00:00
|
|
|
|
2022-01-05 05:27:22 +00:00
|
|
|
fn Home(cx: Scope) -> Element {
|
|
|
|
cx.render(rsx! {
|
2022-02-11 02:00:15 +00:00
|
|
|
h1 { "Home" }
|
2022-01-05 05:27:22 +00:00
|
|
|
})
|
|
|
|
}
|
2021-11-22 20:22:42 +00:00
|
|
|
|
2022-01-05 05:27:22 +00:00
|
|
|
fn BlogList(cx: Scope) -> Element {
|
2021-11-22 20:22:42 +00:00
|
|
|
cx.render(rsx! {
|
2022-02-11 02:00:15 +00:00
|
|
|
div { "Blog List" }
|
2021-11-22 20:22:42 +00:00
|
|
|
})
|
2022-01-05 05:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn BlogPost(cx: Scope) -> Element {
|
|
|
|
let id = use_route(&cx).segment::<usize>("id")?;
|
2022-02-11 02:00:15 +00:00
|
|
|
cx.render(rsx! { div { "{id:?}" } })
|
2022-01-05 05:27:22 +00:00
|
|
|
}
|