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.
Hook macros
Section titled “Hook macros”| 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(). |
Definition macros
Section titled “Definition macros”| 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()). |
Usage notes
Section titled “Usage notes”- 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 toBlocker::new(see Navigation Blockers).
Example
Section titled “Example”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..."), }}Related
Section titled “Related”ComponentsThe router UI components — Link, Outlet, Awaited, SuspenseBoundary, ScrollRestor
Core TypesThe engine types re-exported from navi-router-core — Location, RouteTree, Router
Workspace CratesThe seven crates of the navi workspace and what each one owns.
