我的React原生版本如下
>react-native -v
react-native-cli: 2.0.1
react-native: 0.49.5
我正在尝试使用我的旧演示从一个屏幕重定向到另一个屏幕它反应导航工作正常但现在
这是我的app.js
import {
StackNavigator,
} from 'react-navigation';
import Login from './login';
import Register from './register';
const Nav = StackNavigator({
RootScreen: {screen: Login},
RegisterScreen: {screen: Register}
});
export default class App extends Component {
renderScene(route, navigator){
if(route.name == 'login'){
return <Login navigator={navigator} />
}
if(route.name == 'register'){
return <Register navigator={navigator} />
}
}
render() {
return (
<View style={styles.container}>
<Login />
</View>
);
}
}
这里是login.js,如果用户是app的新用户将重定向到注册屏幕
import { StackNavigator } from 'react-navigation';
export default class Register extends Component {
static navigationOptions = {
title: 'Register',
header: null
};
constructor(props){
super(props);
this.state = {
txtUserName:'',
txtEmail:'',
txtPassword:'',
txtConfPass:''
};
}
render() {
return ( here is design for and button which calls _signUpPage function );
}
_signUpPage = () => {
const { navigate } = this.props.navigation;
this.props.navigation.navigate('Register');
}
}
但它返回错误
TypeError: undefined is not an object (evaluating 'this.props.navigation.navigate')
请检查错误图片