为什么我收到一个错误,指出我的 React Native Navigator 组件中undefined
route
?我以为我推送了正确的信息,但我想不是吗?任何帮助将不胜感激。我习惯于使用网络,所以 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 本机导航器中,我这样做...
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}
/>
)
}
}
路由在开始时未定义,因为您没有为Navigator
提供任何初始路由。你想要设置props initialRoute或initialRouteStack中的任何一个。
假设您要从名为 HOME 的路由开始,下面是一个内联定义路由{ name: 'HOME' }
的示例:
render () {
return (
<Navigator
initialRoute={{ name: 'HOME' }}
configureScene={this.configureScene}
renderScene={this.renderScene}
/>
)
}
通常导航设置如下:
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} />
}