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

Can't read property 'router' of null #2049

Closed
xilibro opened this issue Jul 17, 2017 · 12 comments
Closed

Can't read property 'router' of null #2049

xilibro opened this issue Jul 17, 2017 · 12 comments

Comments

@xilibro
Copy link

xilibro commented Jul 17, 2017

"react": "16.0.0-alpha.12",
"react-native": "0.46.1",
"react-native-router-flux": "^4.0.0-beta.11",

<Router> <Scene key='login' component={LoginForm} title='Login' /> </Router>

when i run my code,give me following error message:
'Can't read property 'router' of null'
in Router.js 279:46

@aksonov
Copy link
Owner

aksonov commented Jul 17, 2017

You must have container scene as root. Otherwise this component doesn't make any sense.

@aksonov aksonov closed this as completed Jul 17, 2017
@ranasing
Copy link

ranasing commented Aug 1, 2017

Can you explain what you mean by this, 'container scene as root'? I am getting the same error. Thanks

@ranasing
Copy link

ranasing commented Aug 1, 2017

Ok, I'm not getting the error any more, but it only shows a blank screen on my Android simulator. Here is the relevant code:

import React, { Component } from 'react';
import { Scene, Router } from 'react-native-router-flux';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import LoginForm from './components/LoginForm';

render() {
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

return (
  <Provider store={store}>
    <Router>
      <Scene key='login' component={LoginForm} title='Login' />
    </Router>
  </Provider>
);

}

**** Only showing render method, because if I take out components and replace with just LoginForm component, it will render correctly.

@aksonov
Copy link
Owner

aksonov commented Aug 1, 2017 via email

@alfchee
Copy link

alfchee commented Aug 2, 2017

@ranasing you should check the documentation, you need to nest all you scenes in the root scene as in the example:

<Router>
    <Scene key="root">
      <Scene key="login" component={Login} title="Login"/>
      <Scene key="home" component={Home}/>
    </Scene>
  </Router>

@mariobermudezjr
Copy link

@alfchee This solved it, thank you so much!! I am two weeks into the Udemy course The Complete React Native and Redux Course by Stephen Grider.

He does the code on his example like @ranasing showed here.

@SarasArya
Copy link

SarasArya commented Aug 15, 2017

@TeslaMotors91 came here after that course as well. This does it. He doesn't use the "root" thing. Hence the issue.

@muhammedbasilsk
Copy link

@alfchee thanks for the help...

<Router>
    <Scene key="root">
      <Scene key="login" component={Login} title="Login"/>
      <Scene key="home" component={Home}/>
    </Scene>
 </Router>

@atljoseph
Copy link

atljoseph commented Oct 19, 2017

@aksonov the guy asked a question and did not get a commensurate response. If you take the time to answer a question, do it fully please.

@lichao0817
Copy link

@alfchee This is really helpful!

@obetomuniz
Copy link

@TeslaMotors91 @SarasArya In the Stephen Grider course, he is using a different version of this library.

@blackinitial
Copy link

Sthepen Grider use 3.35.0 version, but i choose to use last version and got same error like this issue..
Thanks for all, for the answer...

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

No branches or pull requests