Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Navigation Back Button

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!

like image 401
Asleepace Avatar asked Apr 16 '26 23:04

Asleepace


1 Answers

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

like image 116
Asleepace Avatar answered Apr 18 '26 23:04

Asleepace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!