Skip to main content

Route

Route is one entry inside a Router.

It says, "when the current path looks like this pattern, build this screen." A route does not own navigation state. It is only a matcher plus a builder. Your app state still owns the current path string, and your reducers still decide when that path changes.

The current implementation keeps route syntax intentionally small and predictable:

  • literal segments such as /settings
  • named parameters such as /users/:id
  • exact segment counts only

There is no built-in wildcard matching, query-string parsing, or browser-history integration here.

Example

use std::sync::Arc;
use fission::prelude::*;

let project_route = Route {
path: "/projects/:id".into(),
builder: Arc::new(|ctx, view, params: &RouteParams| {
let id = params.get("id").cloned().unwrap_or_default();
ProjectDetail { id }.build(ctx, view)
}),
};

Rust stores the builder in an Arc so the router can own and reuse it across builds.

Field table

FieldTypeMeaningNotes / default behavior
pathStringRoute pattern to match against Router.current_path.Use literal segments and :name parameter segments.
builderPageBuilder<S>Function that builds the route's screen after a match succeeds.Receives &mut BuildCtx<S>, &View, and &RouteParams.

Builder contract

The builder runs during build(), so treat it like any other function that builds interface output. It should read state, derive any necessary values, and return a Node tree. It should not fetch data, write files, or perform side effects directly.

If the route needs to kick off work, dispatch an explicit action and let the reducer or effect system do that in the right place.

Specific advice

Keep route builders thin. The cleanest pattern is usually to extract a real screen widget and have the route builder hand the parsed params into that widget. That keeps the routing table readable and makes the screen easier to test in isolation.

Also validate parameter parsing locally. Matching /projects/:id only guarantees that there was some text in that segment, not that the text is a valid project id.

Router, RouteParams, and Runtime model.