From f5496482ca3225cd786c36a0f39e8c7ab1ea0184 Mon Sep 17 00:00:00 2001
From: lausek <32076279+lausek@users.noreply.github.com>
Date: Sun, 21 Nov 2021 18:50:28 +0100
Subject: [PATCH] Improve documentation of the router (#2166)
* docs: how to add parameters on route
* docs: how to listen for route changes
* docs: how to link to parameterized routes
* docs: router polish
* docs: make router tests pass
---
website/docs/concepts/router.md | 61 +++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/website/docs/concepts/router.md b/website/docs/concepts/router.md
index 1dd6314b834..838eb42c0e0 100644
--- a/website/docs/concepts/router.md
+++ b/website/docs/concepts/router.md
@@ -135,6 +135,42 @@ fn app() -> Html {
}
```
+### Path Segments
+
+It is also possible to extract information from a route.
+
+```rust
+# use yew_router::prelude::*;
+#[derive(Clone, Routable, PartialEq)]
+enum Route {
+ #[at("/")]
+ Home,
+ #[at("/post/:id")]
+ Post { id: String },
+ // ...
+}
+```
+
+You can then access the post's id inside `` and forward it to the appropriate component via properties.
+
+```rust ,ignore
+fn switch(routes: &Route) -> Html {
+ match routes {
+ Route::Home => html! {