You block navigation when the user is about to lose unsaved work. A blocker is a guard that Navi consults before a navigation is applied; it can be synchronous or asynchronous.
Create a blocker
Section titled “Create a blocker”The use_blocker! macro wraps an expression in a Blocker:
use navi_macros::use_blocker;
let blocker = use_blocker!(form.is_dirty());The expression decides whether navigation should be blocked: while form.is_dirty() evaluates to true, navigations away from the route are held.
Async blockers
Section titled “Async blockers”Because blockers guard against data loss, they often need to ask the user first. An async blocker can await that confirmation before it lets the navigation proceed or cancels it — for example, opening a modal and resolving after the user answers.
Bypassing a blocker
Section titled “Bypassing a blocker”NavigateOptions carries an ignore_blocker flag. Setting it to true pushes a navigation past registered blockers — appropriate for programmatic flows that already obtained consent:
let opts = NavigateOptions { ignore_blocker: true, ..Default::default()};navigator.push_location_with(Location::new("/goodbye"), &opts);