simple.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #![allow(non_snake_case)]
  2. use dioxus_core::prelude::*;
  3. use dioxus_core_macro::*;
  4. use dioxus_html as dioxus_elements;
  5. use dioxus_router::*;
  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. fn app(cx: Scope) -> Element {
  12. cx.render(rsx! {
  13. Router {
  14. h1 { "Your app here" }
  15. ul {
  16. Link { to: "/", li { "home" }}
  17. Link { to: "/blog", li { "blog" }}
  18. Link { to: "/blog/tim", li { "tims' blog" }}
  19. Link { to: "/blog/bill", li { "bills' blog" }}
  20. }
  21. Route { to: "/", Home {} }
  22. Route { to: "/blog/", BlogList {} }
  23. Route { to: "/blog/:id/", BlogPost {} }
  24. }
  25. })
  26. }
  27. fn Home(cx: Scope) -> Element {
  28. cx.render(rsx! {
  29. h1 { "Home" }
  30. })
  31. }
  32. fn BlogList(cx: Scope) -> Element {
  33. cx.render(rsx! {
  34. div { "Blog List" }
  35. })
  36. }
  37. fn BlogPost(cx: Scope) -> Element {
  38. let id = use_route(&cx).segment::<usize>("id")?;
  39. cx.render(rsx! { div { "{id:?}" } })
  40. }