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::*;
|
2021-12-29 04:20:01 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-11-19 05:49:04 +00:00
|
|
|
|
|
|
|
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));
|
2021-12-15 20:56:53 +00:00
|
|
|
dioxus_web::launch(APP);
|
2021-11-19 05:49:04 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 04:48:25 +00:00
|
|
|
static APP: Component = |cx| {
|
2022-01-05 05:27:22 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
Router {
|
|
|
|
onchange: move |route| log::info!("route changed to {}", route),
|
|
|
|
Route { to: "/", Home {} }
|
|
|
|
Route { to: "blog"
|
|
|
|
Route { to: "/", BlogList {} }
|
|
|
|
Route { to: ":id", BlogPost {} }
|
|
|
|
}
|
2021-12-29 04:20:01 +00:00
|
|
|
}
|
2022-01-05 05:27:22 +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! {
|
|
|
|
div {
|
|
|
|
h1 { "Home" }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
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! {
|
|
|
|
div {
|
2022-01-05 05:27:22 +00:00
|
|
|
|
2021-11-19 05:49:04 +00:00
|
|
|
}
|
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")?;
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|