Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to see if a Screen/Route exists in a navigation stack for React Navigation v5?

Depending on if a screen exists in a certain stack I need to be able to do different things in my code. I have tried my best but I haven't found anything on the matter. Is there an easy way to achieve this?

like image 209
Aaron Avatar asked Oct 22 '25 22:10

Aaron


2 Answers

In v.6 :

const navigation = useNavigation();
const routes = navigation.getState().routeNames;
like image 193
Vaggelis Avatar answered Oct 27 '25 02:10

Vaggelis


If you mean, you want to get all the routes inside the current navigator, then I think this will fix your problem.

const navigation = useNavigation();

const routes = navigation.dangerouslyGetState().routeNames;
like image 44
Fahad Farooq Avatar answered Oct 27 '25 03:10

Fahad Farooq



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!