web_router.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #![cfg(target_arch = "wasm32")]
  2. #![allow(non_snake_case)]
  3. use dioxus::prelude::*;
  4. use dioxus_router::*;
  5. use gloo_utils::document;
  6. use wasm_bindgen_test::*;
  7. wasm_bindgen_test_configure!(run_in_browser);
  8. #[wasm_bindgen_test]
  9. fn simple_test() {
  10. fn main() {
  11. console_error_panic_hook::set_once();
  12. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  13. dioxus_web::launch(APP);
  14. }
  15. static APP: Component = |cx| {
  16. cx.render(rsx! {
  17. Router {
  18. onchange: move |route: RouterService| log::trace!("route changed to {:?}", route.current_location()),
  19. active_class: "is-active",
  20. Route { to: "/", Home {} }
  21. Route { to: "blog"
  22. Route { to: "/", BlogList {} }
  23. Route { to: ":id", BlogPost {} }
  24. }
  25. }
  26. })
  27. };
  28. fn Home(cx: Scope) -> Element {
  29. cx.render(rsx! {
  30. div {
  31. h1 { "Home" }
  32. }
  33. })
  34. }
  35. fn BlogList(cx: Scope) -> Element {
  36. cx.render(rsx! {
  37. div {
  38. }
  39. })
  40. }
  41. fn BlogPost(cx: Scope) -> Element {
  42. let _id = use_route(&cx).parse_segment::<usize>("id")?;
  43. cx.render(rsx! {
  44. div {
  45. }
  46. })
  47. }
  48. main();
  49. let _ = document();
  50. }