2022-01-05 05:27:22 +00:00
# Routing for Dioxus App
2021-11-19 05:49:04 +00:00
2022-01-05 05:27:22 +00:00
DioxusRouter adds React-Router style routing to your Dioxus apps. Works in browser, SSR, and natively.
2021-11-19 05:49:04 +00:00
```rust
2022-01-05 05:27:22 +00:00
fn app() {
cx.render(rsx! {
2022-01-25 20:06:37 +00:00
Router {
2022-01-05 05:27:22 +00:00
Route { to: "/", Component {} },
Route { to: "/blog", Blog {} },
Route { to: "/blog/:id", BlogPost {} },
}
})
2021-11-19 05:49:04 +00:00
}
2022-01-05 05:27:22 +00:00
```
2021-11-19 05:49:04 +00:00
2022-01-05 05:27:22 +00:00
Then, in your route, you can choose to parse the Route any way you want through `use_route` .
```rust
2022-01-22 03:43:43 +00:00
let id: usize = use_route(&cx).segment("id")?;
2022-01-05 05:27:22 +00:00
let state: CustomState = use_route(&cx).parse()?;
2021-11-19 05:49:04 +00:00
```
Adding links into your app:
```rust
2022-01-05 05:27:22 +00:00
Link { to: "id/{id}" }
2021-11-19 05:49:04 +00:00
```
Currently, the router is only supported in a web environment, but we plan to add 1st-party support via the context API when new renderers are available.