Learn

Call a typed route

Navigate through a destination with context or an injected port, preserving placement and typed results.

v2.4.1Intermediateark_navigation

A destination already declares its input and pop-result type. Call the operation on that value; no generated helper or repeated result-type argument is needed:

dart
final NavigationTicket<bool> ticket =
    const ProductDestination(productId: 'keyboard-42').push(context);

final NavigationOperationResult commit = await ticket.committed;
if (commit is! NavigationCommitted) {
  return; // A Guard rejected the request or resolution failed.
}

final NavigationCompletion<bool> completion = await ticket.completed;
if (completion case NavigationPopped<bool>(:final result)) {
  // result is bool?; Back may pop without a value.
}

For a button, the handler is simply:

dart
onPressed: () {
  const ProductDestination(productId: 'keyboard-42').push(context);
},

After awaiting unrelated work, check context.mounted before using it. Destination methods reject an unmounted context and a context outside an ArkNavigationScope; there is no fallback global router.

The operation states exactly what changes

Destination methodEffectReturn
push(context)Adds an entryNavigationTicket<R>
replaceTop(context)Removes the top entry and creates a new lifecycleNavigationTicket<R>
reconfigureTop(context)Updates a matching top entry, preserving its identity and ticketFuture<NavigationOperationResult>
replaceAll(context)Makes this destination the only entry in its selected stackFuture<NavigationOperationResult>
pushAndRemoveUntil(context, retain: matcher)Retains an anchor, removes its tail and pushes this destinationNavigationTicket<R>

A rewrite completes removed entries as NavigationRemoved<R>, not as a successful typed pop. replaceAll does not clear every tab or session. Default browser history is push for push operations and replace for replacements; each method accepts an explicit historyMode.

Outside widgets: select an injected port

A Presenter does not need a BuildContext. Its owner supplies the narrow NavigationPort, and the destination selects it explicitly:

dart
final NavigationTicket<bool> ticket =
    const ProductDestination(productId: 'keyboard-42')
        .on(navigation)
        .push();

The returned NavigationDestinationActions<bool> is a non-owning target/port binding. It creates no session, installs no Zone and performs no operation until a method is called. Independent ports stay independent across await. The existing navigation.push(destination) API remains supported.

Choose placement, not a hidden navigator

context selects the nearest session. The Graph still selects the destination's Mount and Scope. A call made in a tab can therefore open a route mounted at the root without accidentally placing it in the tab.

For a route mounted more than once, select its exact placement:

dart
final NavigationTarget<bool> target =
    const ProductDestination(productId: 'keyboard-42').placed(
  mountId: const NavigationMountId('catalog-tab'),
);
final NavigationTicket<bool> ticket = target.push(context);

Use an ID actually declared in your Graph. A NavigationTarget<R> has the same five methods and an on(port) binding; it preserves Mount, Scope and presentation. Passing scopeId explicitly filters placements when no Mount is supplied. Supplying both Mount and Scope explicitly can override that Mount's normal Scope; do so only when the application's placement contract intends it.

Ark Navigation never picks the first of several matching Mounts. Ambiguous requests produce NavigationFailed in ticket.committed.

For an existing entry use navigation.pop, popUntil or remove. A destination value is not an entry identity, so it cannot unambiguously choose which duplicate entry to pop. Multi-destination rewrites remain on NavigationPort.