Skip to main content

StackActions reference

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

For screens inside a Stack Navigator or Native Stack Navigator, all stack actions are available as methods on the navigation object.

The following actions are supported:

replace

The replace action allows to replace a route in the navigation state. It takes the following arguments:

  • name - string - A destination name of the route that has been registered somewhere.
  • params - object - Params to pass to the destination route.
navigation.replace('Profile', { user: 'Wojtek' });

It can also be used with navigation.dispatch:

import { StackActions } from '@react-navigation/native';

navigation.dispatch(StackActions.replace('Profile', { user: 'Wojtek' }));

If you want to replace a particular route, you can add a source property referring to the route key and target property referring to the navigation state key:

import { StackActions } from '@react-navigation/native';

navigation.dispatch({
...StackActions.replace('Profile', {
user: 'jane',
}),
source: route.key,
target: navigation.getState().key,
});

If the source property is explicitly set to undefined