为什么我的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}
/>
)
}
}
答案 0 :(得分:2)
路线未定义,因为您未向Navigator
提供任何初始路线。您想要设置道具initialRoute或initialRouteStack。
假设你想从一个名为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} />
}