Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how the get the current route key #652

Closed
musicode opened this issue Mar 11, 2017 · 14 comments
Closed

how the get the current route key #652

musicode opened this issue Mar 11, 2017 · 14 comments

Comments

@musicode
Copy link

route key' format is like id-1489246424348-0, it is useful with goBack(key)

but how can i get the key?

@junshengpierre
Copy link

You access it with this.props.navigation.state.key in your screen component.

@musicode
Copy link
Author

@junshengpierre this.props.navigation.state.key is not the runtime key

@junshengpierre
Copy link

junshengpierre commented Mar 14, 2017

@musicode Are you sure you are passing the right key? Passing a key into this.props.navigation.goBack() brings you back from the route of the key.

this.props.navigation.goBack(screen1Key) brings you to screen0.
this.props.navigation.goBack(screen5Key) brings you to screen4.

Could it be that you are passing screen4Key thinking that it will navigate to screen4?

@ericvicenti
Copy link
Contributor

@junshengpierre has the right answers here

@musicode
Copy link
Author

@junshengpierre

the stack is like A -> form screen -> form result screen, if the current screen is form result, when i press back, i want to skip form screen, back to the A directly.

how can i do that?

@oliverbenns
Copy link

oliverbenns commented May 15, 2017

Cannot access with navigation.state.key (maybe since update). Ended up doing this kinda knarly solution. I needed this to set active state on tab bar. Not exactly sure what the difference is between key and route name.

const { state } = navigation;
const currentRouteKey = state.routes[state.index].key;

@ollyde
Copy link

ollyde commented Aug 24, 2017

navigation.state.routes[state.index].key;

Navigator has no property 'routes'

@carlosconnected
Copy link

I'm experiencing the same as @voidstarfire. No routes in the navigation state.

@WhatAKitty
Copy link

+1 no routes in the navigation state, how can I get the routes?
by onNavigationStateChange?

@shettayyy
Copy link

The state doesn't have routes or index.

@hoscarcito
Copy link

+1

@Versus2017
Copy link

Is there any solutions for this problem ? I think it confuses a lot of people, cause the function of getting current routes or index is important for us.

@rolldone
Copy link

+1

@brentvatne
Copy link
Member

can someone who can explain this issue clearly and provide a reproducible example to demonstrate it on https://snack.expo.io or in a github repository, please create a new issue following the template? (please don't post your entire app, just a small one to reproduce the problem). thanks!

@react-navigation react-navigation locked and limited conversation to collaborators Feb 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests