React Native Navigator Route对象未定义

时间:2017-01-05 23:21:12

标签: javascript reactjs react-native react-native-navigation

为什么我的React Native Navigator组件中出现routeundefined的错误?我以为我正在推送正确的信息,但我猜不是吗?任何帮助,将不胜感激。我过去常常在网上工作,所以React Native非常有变化。

因此...

我想从我的SplashContainer组件导航到我的SignUpForm组件。所以在SplashContainer我这样做......

class SplashContainer extends Component {
    handleLoginFinished = () => {
        this.props.dispatch(handleAuthWithFirebase())
    }
    handleToSignUp = () => {
        this.props.navigator.push({
            signUpForm: true
        });
    }
    handleToSignIn = () => {
        this.props.navigator.push({
            signIn: true
        })
    }
    render () {

        return (
            <Splash onLoginFinished={this.handleLoginFinished} goToSignUp={this.handleToSignUp} goToSignIn={this.handleToSignIn} />
        )
    }
}

export default connect()(SplashContainer)

然后在React Native Navigator中我这样做......

export default class NimbusNavigator extends Component {
    static propTypes = {
        isAuthed: PropTypes.bool.isRequired
    }
    renderScene = (route, navigator) => {
        // Keeps track of whether user is Authed or not. 
        if (this.props.isAuthed === false) {
            return <SplashContainer navigator={navigator}/>
        } else if (route.signUpForm === true) {
            return <SignUpForm navigator={navigator}/>
        }

        return <FooterTabsContainer navigator={navigator} />
    }
    configureScene = (route) => {

    }
    render () {
        return (
            <Navigator
                configureScene={this.configureScene}
                renderScene={this.renderScene}
            />
        )
    }
}

2 个答案:

答案 0 :(得分:2)

路线未定义,因为您未向Navigator提供任何初始路线。您想要设置道具initialRouteinitialRouteStack

假设你想从一个名为HOME的路线开始,这里是一个内联定义路线{ name: 'HOME' }的例子:

render () {
    return (
        <Navigator
            initialRoute={{ name: 'HOME' }}
            configureScene={this.configureScene}
            renderScene={this.renderScene}
        />
    )
}

答案 1 :(得分:0)

通常导航设置如下:

  handleToSignUp = () => {
        this.props.navigator.push({
            name: 'signUpForm'
        });
    }

//

renderScene = (route, navigator) => {
    // Keeps track of whether user is Authed or not. 
    if (this.props.isAuthed === false) {
        return <SplashContainer navigator={navigator}/>
    } else if (route.name === 'signUpForm') {
        return <SignUpForm navigator={navigator}/>
    }

    return <FooterTabsContainer navigator={navigator} />
}