2
votes

I am using react-navigation for my application and I have a navigation stack like this:

Home > Open > View

I would like to go back from View to Home, but I am having some difficulty with the navigation.goBack() function. Basically, this is what I have so far:

navigation.goBack('Home');

What I have found out so far is that the goBack function takes a parameter 'key' which in the docs seems like the routeName, however on closer inspection on my console I can see that the key for my 'Home' page is not the same as the routeName.

My question is how can I find the corresponding 'key' to my 'Home' page? The weird thing is I can see it actually everytime I load a page because the react-navigation prints 'Navigation Dispatch' to the console with all of its properties, I just am not sure how to access these items.

Any help would be greatly appreciated thanks!

2

2 Answers

3
votes

Ok after much trial and error it turns out this is the solution is to pass the key of the view you want to goBack from, in the case of my stack:

Home > Open > View

I needed to pass the key of 'Open' to the goBack function in 'View' in order to go back to 'Home'. Not sure why is was so complicated, here is the thread that finally helped me solve this:

https://github.com/react-community/react-navigation/issues/1481

0
votes
navigation.popToTop();

Goes back to the top of the stack.