You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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]>
Copy file name to clipboardexpand all lines: docs/next/router.md
+13-8
Original file line number
Diff line number
Diff line change
@@ -27,17 +27,18 @@ with `sycamore v0.5.x`).
27
27
28
28
## Creating routes
29
29
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
31
31
top of your source code. This imports the symbols needed to define our router.
32
32
33
33
The heart of the router is an `enum`. Each variant of the `enum` represents a
34
34
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.
36
37
37
38
Here is an example:
38
39
39
40
```rust
40
-
#[derive(Route)]
41
+
#[derive(Route, Clone)]
41
42
enumAppRoutes {
42
43
#[to("/")]
43
44
Index,
@@ -175,23 +176,23 @@ Routes can also be nested! The following code will route any url to `/route/..`
175
176
to `Nested`.
176
177
177
178
```rust
178
-
#[derive(Route)]
179
+
#[derive(Route, Clone)]
179
180
enumNested {
180
181
#[to("/nested")]
181
182
Nested,
182
183
#[not_found]
183
184
NotFound,
184
185
}
185
186
186
-
#[derive(Route)]
187
+
#[derive(Route, Clone)]
187
188
enumAdmin {
188
189
#[to("/console")]
189
190
Console,
190
191
#[not_found]
191
192
NotFound,
192
193
}
193
194
194
-
#[derive(Route)]
195
+
#[derive(Route, Clone)]
195
196
enumRoutes {
196
197
#[to("/")]
197
198
Home,
@@ -215,7 +216,7 @@ view! {
215
216
view=|route:ReadSignal<AppRoutes>| {
216
217
view! {
217
218
div(class="app") {
218
-
(matchroute.get() {
219
+
(matchroute.get_clone() {
219
220
AppRoutes::Index=>view! {
220
221
"This is the index page"
221
222
},
@@ -265,7 +266,7 @@ view! {
265
266
view=|route:ReadSignal<AppRoutes>| {
266
267
view! {
267
268
div(class="app") {
268
-
(matchroute.get() {
269
+
(matchroute.get_clone() {
269
270
AppRoutes::Index=>view! {
270
271
"This is the index page"
271
272
},
@@ -303,3 +304,7 @@ view! {
303
304
a(href="path", rel="external") { "Path" }
304
305
}
305
306
```
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.
0 commit comments