main.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use std::rc::Rc;
  2. use dioxus::{prelude::*, web::HashHistory};
  3. fn main() {
  4. dioxus::LaunchBuilder::new()
  5. .with_cfg(dioxus::web::Config::new().history(Rc::new(HashHistory::new(false))))
  6. .launch(|| {
  7. rsx! {
  8. Router::<Route> {}
  9. }
  10. })
  11. }
  12. #[derive(Routable, Clone, PartialEq)]
  13. #[rustfmt::skip]
  14. enum Route {
  15. #[redirect("/",|| Route::Other)]
  16. #[route("/other")]
  17. Other,
  18. #[route("/other/:id")]
  19. OtherId { id: String },
  20. #[route("/:..segments")]
  21. NotFound { segments: Vec<String> },
  22. }
  23. #[component]
  24. fn Other() -> Element {
  25. rsx! {
  26. div {
  27. id: "other",
  28. "Other"
  29. }
  30. Link {
  31. id: "other-id-link",
  32. to: Route::OtherId { id: "123".to_string() },
  33. "go to OtherId"
  34. }
  35. }
  36. }
  37. #[component]
  38. fn OtherId(id: String) -> Element {
  39. rsx! {
  40. div {
  41. id: "other-id",
  42. "OtherId {id}"
  43. }
  44. }
  45. }
  46. #[component]
  47. fn NotFound(segments: Vec<String>) -> Element {
  48. rsx! {
  49. div {
  50. id: "not-found",
  51. "NotFound {segments:?}"
  52. }
  53. }
  54. }