1
0

router.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //! Dioxus Router
  2. //! -------------
  3. //!
  4. //! This exmaple showcases the Dioxus Router hook. This hook makes it possible to using the browser's navigation API to
  5. //! display different content based on the Page's URL. The hook provides a configuration object that calls various
  6. //! specified callbacks whenever the page URL changes. Using this hook should feel like building a "URL directory", similar
  7. //! to how Tide handles paths.
  8. use dioxus::prelude::*;
  9. fn main() {
  10. diouxs_webview::launch(App).run().await
  11. }
  12. fn App(ctx: Context<()>) -> VNode {
  13. let router = use_router(&ctx, |router| {
  14. //
  15. router.get("/dogs/:dogId/").render(|ctx, request| {
  16. rsx! {
  17. div {
  18. }
  19. }
  20. });
  21. router.get("/cats/:catId/").render(|ctx, request| {
  22. rsx! {
  23. div {
  24. }
  25. }
  26. });
  27. });
  28. ctx.render(rsx! {
  29. div {
  30. a { href: "/dogs/"}
  31. a { href: "/cats/"}
  32. {router.render()}
  33. }
  34. })
  35. }