Skip to content
Advertisement

How to get previous route name from React Navigation

I am trying to get previous route name to my current screen. Because based on the previous screen name, I have to show/hide few objects in current screen.

To get previous screen name, I have tried following

JavaScript

But, It’s getting undefined in console log.

Any suggestions?

Advertisement

Answer

You need to use NavigationActions

JavaScript

call the above function in your onPress

JavaScript

In your other screen

JavaScript

Working demo

Function version

JavaScript

And access the params like

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement