catch_all.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use dioxus_router::prelude::*;
  4. // ANCHOR: router
  5. #[derive(Routable, Clone)]
  6. enum Route {
  7. #[route("/")]
  8. Home {},
  9. // PageNotFound is a catch all route that will match any route and placing the matched segments in the route field
  10. #[route("/:..route")]
  11. PageNotFound { route: Vec<String> },
  12. }
  13. // ANCHOR_END: router
  14. // ANCHOR: app
  15. #[inline_props]
  16. fn App(cx: Scope) -> Element {
  17. render! {
  18. Router {}
  19. }
  20. }
  21. // ANCHOR_END: app
  22. // ANCHOR: home
  23. #[inline_props]
  24. fn Home(cx: Scope) -> Element {
  25. render! {
  26. h1 { "Welcome to the Dioxus Blog!" }
  27. }
  28. }
  29. // ANCHOR_END: home
  30. // ANCHOR: fallback
  31. #[inline_props]
  32. fn PageNotFound(cx: Scope, route: Vec<String>) -> Element {
  33. render! {
  34. h1 { "Page not found" }
  35. p { "We are terribly sorry, but the page you requested doesn't exist." }
  36. pre {
  37. color: "red",
  38. "log:\nattemped to navigate to: {route:?}"
  39. }
  40. }
  41. }
  42. // ANCHOR_END: fallback
  43. fn main() {}