RouteParams
RouteParams is a HashMap<String, String> containing values captured from
a matched route. For example, a Router matching
/projects/:id puts the :id segment in this map. This is intentionally simple. Route parameters are just text. The router does not guess whether :id should be a number, a universally unique identifier (UUID), or a slug. Your route builder parses and validates that value according to your product rules.
Example
use fission::prelude::*;
fn parse_project_id(params: &RouteParams) -> Option<u64> {
params
.get("id")
.and_then(|value| value.parse::<u64>().ok())
}
route_component supplies the same captured map as a build-scoped provider so
a named component does not have to fall back to an anonymous builder:
fission_component! {
pub ProjectRoute<AppState>
view(_route, _state, _cx) {
let params = fission::build::read::<RouteParams>();
let project_id = parse_project_id(¶ms);
} =>
match project_id {
Some(id) => ProjectScreen(id),
None => ProjectNotFound(),
}
}
ProjectScreen accepts a validated u64; ProjectNotFound handles a missing
or malformed segment. The branches are different components, but Compose
converts both to Widget. The application must still check that the parsed
project exists and that the current user may open it.
The map exists only during conversion of the matched route. Copy the values a
component needs into ordinary widget fields or actions; do not retain a
build-scope handle.
Entry table
| | | |
|---|
| | The parameter name from the route pattern, without the leading :. | For /projects/:id, the key is "id". |
| | The raw text from the matched route or path segment. | Always parse or validate before using it as a typed identifier. |
Specific advice
Treat route params as untrusted strings, even in desktop apps. A malformed deep link, an outdated bookmark, or a bug in your own navigation reducer can still put unexpected data here.
Also note what RouteParams does not contain: query strings, hash fragments, or wildcard path tails. The current router only supports exact segment matching with named :param segments.
Check route values
Treat every parameter as an untrusted string: parse it, validate it, and handle a missing or invalid value in the route builder.
Remember that RouteParams contains only named path segments. It does not parse query strings, fragments, or wildcard tails.