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

"There is no route defined for key "a" in beta.12-15 #2189

Closed
alexwasner opened this issue Aug 4, 2017 · 14 comments
Closed

"There is no route defined for key "a" in beta.12-15 #2189

alexwasner opened this issue Aug 4, 2017 · 14 comments

Comments

@alexwasner
Copy link

alexwasner commented Aug 4, 2017

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.0.beta.12+
  • react-native v.44.0

Expected behaviour

I should be able to navigate from E to A

Actual behaviour

I get an error thrown

Steps to reproduce

I have an app set up with the following structure:

    render() {
        return (
            <Provider {...stores}>
                <Router createReducer={reducerCreate}
                                      navBarTintColor= {'white'}
                                      navBarButtonColor= {'white'}
                                      tintColor= {'white'} >
                  <Scene key="modal"  hideNavBar modal
                                      navTransparent={true}
                                      drawUnderNavBar={true}
                                      navBarTintColor= {'white'}
                                      navBarButtonColor= {'white'}
                                      tintColor= {'white'}
                                      navigationBarStyle={styles.navBar}
                                      titleStyle={styles.titleStyle}>
                    <Scene key="root"
                                      navBarTintColor= {'white'}
                                      navBarButtonColor= {'white'}
                                      tintColor= {'white'}>
                        <Scene key="a" title="A" component={A} type='reset' />
                        <Scene key="b" title="B" drawUnderNavBar={false} component={B} type='reset' />
                        <Scene key="c" title="C" component={C} />
                        <Scene key="d" title="D" onLeft={Actions.C}
                                          left={<TouchableOpacity onPress={()=>{Actions.G()}}><Image source={{uri:'iconHere'}} style={[styles.headerIcon,styles.leftIcon]}/></TouchableOpacity>}
                                          component={D}/>
                        <Scene key="e" title="E" component={E} initial />
                    </Scene>
                    <Scene key="f"  hideTabBar
                                    navBarTintColor= {'white'}
                                    navBarButtonColor= {'white'}
                                    tintColor= {'white'}>
                        <Scene key="g" leftTitle="Cancel" onLeft={Actions.pop} title="G" component={G}
                                    navBarTintColor= {'white'}
                                    navBarButtonColor= {'white'}
                                    tintColor= {'white'} />
                    </Scene>
                  </Scene>
              </Router>
          </Provider>
        )
    }
}

When launching the app, I got to E which runs a few checks to determine where to navigate to next in componentDidMount. It calls Actions.a() which should navigate. Instead, I get There is no route defined for key a. Must be one of 'root','f'. I tried with a bunch of more routes and still get the same error

@aksonov
Copy link
Owner

aksonov commented Aug 5, 2017

reset fully clears stack, please try to use 'replace' instead or ActionsConsts.POP_AND_PUSH.

@m-vdb
Copy link

m-vdb commented Aug 6, 2017

using RESET worked for me!

@alexwasner
Copy link
Author

alexwasner commented Aug 7, 2017

@aksonov Didn't work as I'm not using a reset here. I have an intermediary screen that calls

LocalStorage.getItem('@UserStore.authenticated').then((val) => {
			if (val && val.isLoggedIn) {
				Actions.a()
			} else {
				Actions.b()
			}
		})```

@alexwasner
Copy link
Author

Oh on the actual Scene itself. Gotcha. That fixed it. Why does reset crash it though?

@m-vdb
Copy link

m-vdb commented Aug 7, 2017

Have you tried using Actions.a({type: ActionConst.RESET})? It will force reseting the navigation stack. I had a similar issue than you I guess, since my user navigated from logged-out state to logged-in state, and I have 2 separate trees for the two states.

Also @asokol don't you think it's worth documenting that somewhere? It's pretty useful and almost every app will implement login/logout

@aksonov
Copy link
Owner

aksonov commented Aug 7, 2017

PR is welcome.

@alexwasner
Copy link
Author

So @aksonov How do I have two routes that can perform a reset? I also tried POP_AND_PUSH and it seems to just do a push. I need to clear the entire stack when logging out and its not doing anything

@alexwasner
Copy link
Author

alexwasner commented Aug 7, 2017

Here's a gif of whats happening with the following setup:

  1. Login calls Actions.home({type:ActionConst.REPLACE}) and it does a hard cut without animation.
  2. Clicking Logout on Home calls this.props.navigation.navigate(login{type:ActionConst.REPLACE}) and it does a PUSH.
  3. I am able to swipe back to Home
  4. Upon second login, the exact same Actions.home({type:ActionConst.REPLACE}) looks like a POP
    test

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2017

@alexwasner Please send me link to repo, it is difficult to say something

@alexwasner
Copy link
Author

I can't share this repo as it's work related and had to remove a bunch of styles just to get that gif to show. If I get time in the next few days, I can strip it down to the bare bones and send a link to that

@alexwasner
Copy link
Author

@aksonov Here is an example of the navigation bug from the gif above. alexwasner@faf4e74

If you launch the app, you can follow exactly with the gif I provided. If you click the "Go to Launch page" on the Home page, and try to click on the the links, you will see the original bug I listed.

@aksonov
Copy link
Owner

aksonov commented Aug 10, 2017

@alexwasner Looks like it happens because react-navigation doesn't have normal 'replace' - i.e. push & pop previous scene. I implement 'replace' with their 'reset' action but it is not real 'replace'.

Now I implemented it as PUSH & POP_PREVIOUS, check now.

P.S. If you use react-navigation navigate it will not do replace, because it is not supported.

aksonov added a commit that referenced this issue Aug 10, 2017
* Fix 'replace' action (#2189)

* Fix issues when replace within deep container

* Compiled sources
@aksonov
Copy link
Owner

aksonov commented Aug 10, 2017

Should be fixed within latest master

@hassanelsherpiny
Copy link

Actions.pop() will do what you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants