3

为什么我的 React Native Navigator 组件中route出现错误?undefined我以为我在推送正确的信息,但我猜不是?任何帮助,将不胜感激。我习惯于使用网络,所以 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}
            />
        )
    }
}
4

2 回答 2

2

该路线在开始时未定义,因为您没有提供Navigator任何初始路线。您想设置道具initialRouteinitialRouteStack

假设您想从名为 HOME 的路由开始,下面是一个{ name: 'HOME' }内联定义路由的示例:

render () {
    return (
        <Navigator
            initialRoute={{ name: 'HOME' }}
            configureScene={this.configureScene}
            renderScene={this.renderScene}
        />
    )
}
于 2017-01-17T07:03:32.817 回答
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} />
}
于 2017-01-05T23:35:59.347 回答