mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-24 04:25:34 +08:00
fix: pop with correct key from nested stack
This commit is contained in:
@@ -47,12 +47,14 @@ const Header = React.memo(function Header(props: StackHeaderProps) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
const goBack = React.useCallback(
|
||||
debounce(() => {
|
||||
if (navigation.isFirstRouteInParent()) {
|
||||
// If we're the first route, we're going back to a parent navigator
|
||||
// So we can't specify a key here
|
||||
navigation.dispatch(StackActions.pop());
|
||||
} else {
|
||||
navigation.dispatch(StackActions.pop({ key: scene.route.key }));
|
||||
const key = navigation.isFirstRouteInParent()
|
||||
? // If we're the first route, we're going back to a parent navigator
|
||||
// So we need to get the key of the route we're nested in
|
||||
navigation.dangerouslyGetParent()?.state.key
|
||||
: scene.route.key;
|
||||
|
||||
if (key !== undefined) {
|
||||
navigation.dispatch(StackActions.pop({ key }));
|
||||
}
|
||||
}, 50),
|
||||
[navigation, scene.route.key]
|
||||
|
||||
Reference in New Issue
Block a user