simple.rs 1003 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. use dioxus_core::prelude::*;
  2. use dioxus_core_macro::*;
  3. use dioxus_html as dioxus_elements;
  4. use dioxus_router::*;
  5. fn main() {
  6. console_error_panic_hook::set_once();
  7. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  8. dioxus_web::launch(App, |c| c);
  9. }
  10. static App: FC<()> = |cx, props| {
  11. #[derive(Clone, Debug, PartialEq)]
  12. enum Route {
  13. Home,
  14. About,
  15. NotFound,
  16. }
  17. let route = use_router(cx, |s| match s {
  18. "/" => Route::Home,
  19. "/about" => Route::About,
  20. _ => Route::NotFound,
  21. });
  22. cx.render(rsx! {
  23. div {
  24. {match route {
  25. Route::Home => rsx!(h1 { "Home" }),
  26. Route::About => rsx!(h1 { "About" }),
  27. Route::NotFound => rsx!(h1 { "NotFound" }),
  28. }}
  29. nav {
  30. Link { to: Route::Home, href: |_| "/".to_string() }
  31. Link { to: Route::About, href: |_| "/about".to_string() }
  32. }
  33. }
  34. })
  35. };