Skip to content

Commit ac8c313

Browse files
lukeh990lukechu10
andauthored
Update router documentation (#788)
* Update router documentation This commit modifies the existing docs to better reflect the example provided in /examples/router/src/main.rs * Update docs/next/router.md Co-authored-by: Luke <[email protected]> * Update docs/next/router.md Co-authored-by: Luke <[email protected]> --------- Co-authored-by: Luke <[email protected]>
1 parent 1f64418 commit ac8c313

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

docs/next/router.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ with `sycamore v0.5.x`).
2727

2828
## Creating routes
2929

30-
Start off by adding `use sycamore_router::{Route, Router, RouterProps}` to the
30+
Start off by adding `use sycamore_router::{Route, Router, HistoryIntegration}` to the
3131
top of your source code. This imports the symbols needed to define our router.
3232

3333
The heart of the router is an `enum`. Each variant of the `enum` represents a
3434
different route. To make our `enum` usable with `Router`, we will use the
35-
`Route` derive macro to implement the required traits for us.
35+
`Route` derive macro to implement the required traits for us. We will also derive the
36+
`Clone` trait which allows the contents to be copied by the router.
3637

3738
Here is an example:
3839

3940
```rust
40-
#[derive(Route)]
41+
#[derive(Route, Clone)]
4142
enum AppRoutes {
4243
#[to("/")]
4344
Index,
@@ -175,23 +176,23 @@ Routes can also be nested! The following code will route any url to `/route/..`
175176
to `Nested`.
176177

177178
```rust
178-
#[derive(Route)]
179+
#[derive(Route, Clone)]
179180
enum Nested {
180181
#[to("/nested")]
181182
Nested,
182183
#[not_found]
183184
NotFound,
184185
}
185186

186-
#[derive(Route)]
187+
#[derive(Route, Clone)]
187188
enum Admin {
188189
#[to("/console")]
189190
Console,
190191
#[not_found]
191192
NotFound,
192193
}
193194

194-
#[derive(Route)]
195+
#[derive(Route, Clone)]
195196
enum Routes {
196197
#[to("/")]
197198
Home,
@@ -215,7 +216,7 @@ view! {
215216
view=|route: ReadSignal<AppRoutes>| {
216217
view! {
217218
div(class="app") {
218-
(match route.get() {
219+
(match route.get_clone() {
219220
AppRoutes::Index => view! {
220221
"This is the index page"
221222
},
@@ -265,7 +266,7 @@ view! {
265266
view=|route: ReadSignal<AppRoutes>| {
266267
view! {
267268
div(class="app") {
268-
(match route.get() {
269+
(match route.get_clone() {
269270
AppRoutes::Index => view! {
270271
"This is the index page"
271272
},
@@ -303,3 +304,7 @@ view! {
303304
a(href="path", rel="external") { "Path" }
304305
}
305306
```
307+
308+
## Examples
309+
Check out the [router example](https://github.com/sycamore-rs/sycamore/blob/main/examples/router/src/main.rs) for more details on how to use the Router API.
310+

0 commit comments

Comments
 (0)