Skip to content

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.

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.

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.

NavigateOptions carries an ignore_blocker flag. Setting it to true pushes a navigation past registered blockers — appropriate for programmatic flows that already obtained consent:

use navi_router::{Location, NavigateOptions};
let opts = NavigateOptions {
ignore_blocker: true,
..Default::default()
};
navigator.push_location_with(Location::new("/goodbye"), &opts);