StackActions is an object containing methods for generating actions specific to stack-based navigators. Its methods expand upon the actions available in
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 action wipes the whole navigation state and replaces it with the result of several actions.
index- number - required - Index of the active route on
routesarray in navigation
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.
How to use the
index param is used to specify the current active route.
eg: given a basic stack navigation with two routes
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:
replace action replaces the route at the given key with another route.
key- string - Key of the route to replace. If this is not defined, the most recent route will be replaced.
newKey- string - Key to use for the replacement route. Generated automatically if not provided.
routeName- string -
routeNameto use for replacement route.
params- object - Parameters to pass in to the replacement route.
action- object - Optional sub-action.
immediate- boolean - Currently has no effect, this is a placeholder for when stack navigator supports animated replace (it currently does not).
push action adds a route on top of the stack and navigates forward to it. This differs from
navigate in that
navigate will pop back to earlier in the stack if a route of the given name is already present there.
push will always add on top, so a route can be present multiple times.
routeName- string -
routeNameto push onto the stack.
params- object - Screen params to merge into the destination route (found in the pushed screen through
action- (advanced) The sub-action to run in the child router, if the screen is a navigator.
pop action takes you back to a previous screen in the stack. The
n param allows you to specify how many screens to pop back by.
n- number - The number of screens to pop back by.
popToTop action takes you back to the first screen in the stack, dismissing all the others. It's functionally identical to