web_router.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #![cfg(feature = "wasm_test")]
  2. #![allow(non_snake_case)]
  3. use std::sync::Arc;
  4. use dioxus::prelude::*;
  5. use dioxus_router::prelude::*;
  6. use gloo::utils::document;
  7. use wasm_bindgen_test::*;
  8. wasm_bindgen_test_configure!(run_in_browser);
  9. #[wasm_bindgen_test]
  10. fn simple_test() {
  11. fn main() {
  12. console_error_panic_hook::set_once();
  13. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  14. dioxus_web::launch(App);
  15. }
  16. fn App(cx: Scope) -> Element {
  17. use_router(
  18. cx,
  19. &|| RouterConfiguration {
  20. on_update: Some(Arc::new(|_| None)),
  21. ..Default::default()
  22. },
  23. &|| {
  24. Segment::content(comp(Home)).fixed(
  25. "blog",
  26. Route::empty().nested(
  27. Segment::content(comp(BlogList)).catch_all((comp(BlogPost, PostId {}))),
  28. ),
  29. )
  30. },
  31. );
  32. render!(Outlet {})
  33. }
  34. fn Home(cx: Scope) -> Element {
  35. cx.render(rsx! {
  36. div {
  37. h1 { "Home" }
  38. }
  39. })
  40. }
  41. fn BlogList(cx: Scope) -> Element {
  42. cx.render(rsx! {
  43. div {
  44. }
  45. })
  46. }
  47. struct PostId;
  48. fn BlogPost(cx: Scope) -> Element {
  49. let _id = use_route(cx)?.parameter::<PostId>().unwrap();
  50. cx.render(rsx! {
  51. div { }
  52. })
  53. }
  54. main();
  55. let _ = document();
  56. }