Skip to content

navi-macros provides the type-safe hooks and route definition macros. All hooks read from the current RouterHandle and are cheap — the per-frame hooks read navigation-time caches and allocate nothing.

Macro Signature What it does
use_params!(RouteType) route type argument Extracts typed path parameters for the route.
use_search!(RouteType) route type argument Extracts typed search/query parameters.
use_loader_data!(RouteType) route type argument Accesses data returned by the route’s loader.
use_loader_state!(RouteType) route type argument Returns the route’s LoaderState from the router state.
use_route_context!(RouteType) route type argument Returns the full typed route context.
use_matched_route!() none Returns (params_map, route_node) for the currently matched route. Panics if nothing matched.
use_match!() none Returns (route_id, params) for the current match, or the default if none.
use_navigate!() none Expands to Navigator::new() — the programmatic navigation handle.
use_blocker!(expr) boolean expression Expands to Blocker::new(expr) — a navigation blocker.
use_can_go_back!() none Expands to Navigator::can_go_back().
Macro Purpose
define_route!(Name, ...) Declares a route with its path, data hooks, and UI — see the define_route! reference.
define_router!(...) Declares a router from a list of route types; expands to the calls that add each route’s node to the tree (tree.add_route(Route::build_node())) and register each component (Route::register()).
  • The typed hooks (use_params!, use_search!, use_loader_data!, use_loader_state!, use_route_context!) take the route type as their argument, so extraction is checked against the route you declare.
  • use_matched_route! expects a matched route — calling it before any navigation matched raises an error by design.
  • use_blocker! accepts any boolean expression; it is the ergonomic path to Blocker::new (see Navigation Blockers).

Two hooks cooperating in one route’s render function:

use navi_macros::{use_loader_data, use_params};
fn user_node() -> Node {
let data = use_loader_data!(UsersParamIdRoute);
match data.map(|d| (*d).clone()) {
Some(user) => Node::text(format!("{} — {}", user.name, user.email)),
None => Node::text("Loading..."),
}
}