null 不是对象(正在计算 'AppNavigator.router')

null is not an object (evaluating 'AppNavigator.router')

**

I need help!! null is not an object (evaluating '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;

实际上,您需要将场景包装在根场景中 <Scene key="root">,文档中未提及。

因此您的 RouterComponent 如下所示:

const RouterComponent = () =>{

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

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

包裹你的 <Scene>
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>
    );
};

只需将当前场景添加到另一个场景中,使用 key="root"

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