web_router.rs 1.5 KB

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