simple.rs 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. use dioxus_core::prelude::*;
  2. use dioxus_core_macro::*;
  3. use dioxus_html as dioxus_elements;
  4. use dioxus_router::*;
  5. use serde::{Deserialize, Serialize};
  6. fn main() {
  7. console_error_panic_hook::set_once();
  8. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  9. dioxus_web::launch(APP);
  10. }
  11. static APP: Component = |cx| {
  12. cx.render(rsx! {
  13. Router {
  14. onchange: move |route| log::info!("route changed to {}", route),
  15. Route { to: "/", Home {} }
  16. Route { to: "blog"
  17. Route { to: "/", BlogList {} }
  18. Route { to: ":id", BlogPost {} }
  19. }
  20. }
  21. })
  22. };
  23. fn Home(cx: Scope) -> Element {
  24. cx.render(rsx! {
  25. div {
  26. h1 { "Home" }
  27. }
  28. })
  29. }
  30. fn BlogList(cx: Scope) -> Element {
  31. cx.render(rsx! {
  32. div {
  33. }
  34. })
  35. }
  36. fn BlogPost(cx: Scope) -> Element {
  37. let id = use_route(&cx).segment::<usize>("id")?;
  38. cx.render(rsx! {
  39. div {
  40. }
  41. })
  42. }