dioxus/packages/router/tests/web_router.rs

61 lines
1.3 KiB
Rust
Raw Normal View History

2022-02-01 19:40:29 +00:00
#![cfg(target_arch = "wasm32")]
#![allow(non_snake_case)]
2022-02-01 19:40:29 +00:00
2022-06-25 16:17:26 +00:00
use dioxus::prelude::*;
2022-02-01 19:40:29 +00:00
use dioxus_router::*;
use gloo_utils::document;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn simple_test() {
fn main() {
console_error_panic_hook::set_once();
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
2022-12-08 00:02:35 +00:00
dioxus_web::launch(app);
2022-02-01 19:40:29 +00:00
}
2022-12-08 00:02:35 +00:00
fn app(cx: Scope) -> Element {
2022-02-01 19:40:29 +00:00
cx.render(rsx! {
Router {
2022-12-08 00:02:35 +00:00
onchange: move |router: RouterContext| log::trace!("route changed to {:?}", router.current_location()),
2022-03-13 16:35:28 +00:00
active_class: "is-active",
2022-02-01 19:40:29 +00:00
Route { to: "/", Home {} }
Route { to: "blog"
Route { to: "/", BlogList {} }
Route { to: ":id", BlogPost {} }
}
}
})
2022-12-08 00:02:35 +00:00
}
2022-02-01 19:40:29 +00:00
fn Home(cx: Scope) -> Element {
cx.render(rsx! {
div {
h1 { "Home" }
}
})
}
fn BlogList(cx: Scope) -> Element {
cx.render(rsx! {
div {
}
})
}
fn BlogPost(cx: Scope) -> Element {
2022-12-08 00:02:35 +00:00
let _id = use_route(cx).parse_segment::<usize>("id").unwrap();
2022-02-01 19:40:29 +00:00
cx.render(rsx! {
2022-12-08 00:02:35 +00:00
div { }
2022-02-01 19:40:29 +00:00
})
}
main();
2022-06-28 23:17:00 +00:00
let _ = document();
2022-02-01 19:40:29 +00:00
}