Skip to main content
Version: 2.x

StackActions reference

StackActions is an object containing methods for generating actions specific to stack-based navigators. Its methods expand upon the actions available in NavigationActions.

The following actions are supported:

  • Reset - Replace current state with a new state
  • Replace - Replace a route at a given key with another route
  • Push - Add a route on the top of the stack, and navigate forward to it
  • Pop - Navigate back to previous routes
  • PopToTop - Navigate to the top route of the stack, dismissing all other routes

reset

The reset action wipes the whole navigation state and replaces it with the result of several actions.

  • index - number - required - Index of the active route on routes array in navigation state.
  • actions - array - required - Array of Navigation Actions that will replace the navigation state.
  • key - string or null - optional - If set, the navigator with the given key will reset. If null, the root navigator will reset.
import { StackActions, NavigationActions } from 'react-navigation';

const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Profile' })],
});
this.props.navigation.dispatch(resetAction);

How to use the index parameter

The index param is used to specify the current active route.

eg: given a basic stack navigation with two routes Profile and Settings. To reset the state to a point where the active screen was Settings but have it stacked on top of a Profile screen, you would do the following:

import { StackActions, NavigationActions } from 'react-navigation';

const resetAction = StackActions.reset({
index