6

Parent Navigator

  • Nested navigator 1

    • Screen A
    • Screen B
  • Nested navigator 2

    • Screen C
    • Screen D

How can I go from Screen D to Screen B in React Navigation v5.0 ?

I tried something similar to https://reactnavigation.org/docs/en/navigation-actions.html#reset

but when I try to use CommonActions.reset(), it navigates to Screen C

I tried this;

    ...
    import { CommonActions } from '@react-navigation/native';
    ...
    navigation.dispatch(
      CommonActions.reset({
        index: 1,
        routes: [
          { name: 'ScreenB' },
        ],
      })
    );
..
1
  • isn't index:1 referring to 2nd nested navigator (which includes C & D) ? Have you tried with index:0 ? Commented Feb 10, 2020 at 16:27

2 Answers 2

2
navigation.navigate('Navigator1', { screen: 'ScreenB' });

https://reactnavigation.org/docs/en/nesting-navigators.html#navigating-to-a-screen-in-a-nested-navigator

Sign up to request clarification or add additional context in comments.

2 Comments

I have a MessagesStack, And i want to navigate to screen in another stack "HomeStack" it works well but when I click to back button it returns me to that stack in the initial screen "HomeStack" not to the MessagesStack, Is there a way to handle it to back me to current stack "MessagesStack"?
For navigating between arbitrarily nested navigators, see: medium.com/swlh/… "What If We Nest More?"
0

Try with

navigation.dispatch(
              CommonActions.reset({
                index: 0,
                routes: [
                  {
                    name: 'Navigator 1',
                    state: {
                      routes: [
                        { name: 'Screen A' },
                        { name: 'Screen B' },
                      ]
                    }
                  }
                ]
              })
            );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.