mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 06:30:20 +00:00
f8a7e1cd82
We don't want to have the router just always match paths as exact strings. If a path contains a parameter like "/thing/:id" then the ":id" portion of the route should match _any_ string, not a literal ":id". |
||
---|---|---|
.. | ||
.vscode | ||
examples | ||
src | ||
Cargo.toml | ||
CHANGELOG.md | ||
README.md |
Routing for Dioxus App
DioxusRouter adds React-Router style routing to your Dioxus apps. Works in browser, SSR, and natively.
fn app() {
cx.render(rsx! {
Routes {
Route { to: "/", Component {} },
Route { to: "/blog", Blog {} },
Route { to: "/blog/:id", BlogPost {} },
}
})
}
Then, in your route, you can choose to parse the Route any way you want through use_route
.
let id: usize = use_route(&cx).path("id")?;
let state: CustomState = use_route(&cx).parse()?;
Adding links into your app:
Link { to: "id/{id}" }
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.