null不是对象(评估'AppNavigator.router')

时间:2017-08-09 14:48:00

标签: react-native redux router react-native-router-flux

**

  

我需要帮助!! null不是对象(评估'AppNavigator.router')

**

/**
 * Created by nihalyorulmaz on 08/08/2017.
 */
import React from 'react';
import { Scene, Router} from 'react-native-router-flux';
import LoginForm from '../../components/components/LoginForm';


const RouterComponent = () => {
    return (
        <Router>
            <Scene key = "login" component = {LoginForm} title = "Please Login"/>
        </Router>
    );
};

export default RouterComponent;

3 个答案:

答案 0 :(得分:3)

实际上你需要将你的场景包装在文档中没有提到的根场景<Scene key="root">中。

所以你的RouterComponent如下所示:

const RouterComponent = () =>{

return(
    <Router>
        <Scene key="root" >
        <Scene key="login" component ={LoginForm} title="Please Login"/>
        </Scene>
    </Router>
);
};

答案 1 :(得分:3)

首先检查react-native-router-flux的版本。如果版本 是3,用<Scene>包裹<Scene key="root" >

const RouterComponent = () => {
    return (
        <Router>
            <Scene key="root">
                <Scene key="login" component={LoginForm} title="Please Login" />
            </Scene>
        </Router>
    );
};

对于版本4,请将<Scene key="root">替换为<Stack key="root">,不要忘记导入import {Stack} from 'react-native-router-flux

import { Router, Scene, Stack } from 'react-native-router-flux';
    const RouterComponent = () => {
    return (
        <Router>
            <Stack key="root">
                <Scene key="login" component={LoginForm} title="Please Login" />
            </Stack>
        </Router>
    );
};

答案 2 :(得分:0)

只需将当前场景添加到另一个具有key =“ root”的场景中

<Scene key="root" >
        <Scene
            key="login"
            component={LoginForm}
            title="Please Login"/>
        </Scene>