Undefined 不是对象(正在计算 'this.props.navigator.replace')
Undefined is not an object (evaluating 'this.props.navigator.replace')
我按照教程使用 React-Navigation,但在尝试移动到另一个页面时遇到问题。我收到此错误:Undefined is not an object (evaluating 'this.props.navigator.replace')
我在这里和其他网站上进行了搜索,但没有任何效果。
这是我的代码:
索引:
import React, { Component } from 'react';
import { Root } from './config/Router';
class Application extends Component{
render(){
return <Root />;
}
}
export default Application;
路由器:
import React from 'react';
import { StackNavigator } from 'react-navigation';
import Login from '../pages/Login';
import Home from '../pages/Home';
export const Root = StackNavigator({
Login:{
screen: Login,
},
Home:{
screen: Home,
navigatorOptions:{
title: "Homepage"
}
}
});
登录(点击此处按钮时出现问题):
export default class Login extends Component{
constructor(props){
super(props);
}
_navigate(routeName){
this.props.navigator.replace({
name: routeName
});
}
render(){
return(
<View style = {styles.container}>
<TouchableOpacity onPress={this._navigate.bind(this, 'Home')}>
<Text>
Hello.
</Text>
</TouchableOpacity>
</View>
);
}
}
我做错了什么?
提前致谢。
根据 the React Native docs,您需要使用 this.props.navigation
导航,而不是 this.props.navigator
:
export default class Login extends Component{
constructor(props){
super(props);
}
_navigate(routeName){
this.props.navigation({
name: routeName
});
}
render(){
return(
<View style = {styles.container}>
<TouchableOpacity onPress={this._navigate.bind(this, 'Home')}>
<Text>
Hello.
</Text>
</TouchableOpacity>
</View>
);
}
}
class HomeScreen extends React.Component {
//Some code here
}
class ChatScreen extends React.Component {
//Some code here
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
AppRegistry.registerComponent('HelloWorld', () => SimpleApp);
您应该注册 "Simple" 而不是 "HomeScreen"
我按照教程使用 React-Navigation,但在尝试移动到另一个页面时遇到问题。我收到此错误:Undefined is not an object (evaluating 'this.props.navigator.replace')
我在这里和其他网站上进行了搜索,但没有任何效果。 这是我的代码:
索引:
import React, { Component } from 'react';
import { Root } from './config/Router';
class Application extends Component{
render(){
return <Root />;
}
}
export default Application;
路由器:
import React from 'react';
import { StackNavigator } from 'react-navigation';
import Login from '../pages/Login';
import Home from '../pages/Home';
export const Root = StackNavigator({
Login:{
screen: Login,
},
Home:{
screen: Home,
navigatorOptions:{
title: "Homepage"
}
}
});
登录(点击此处按钮时出现问题):
export default class Login extends Component{
constructor(props){
super(props);
}
_navigate(routeName){
this.props.navigator.replace({
name: routeName
});
}
render(){
return(
<View style = {styles.container}>
<TouchableOpacity onPress={this._navigate.bind(this, 'Home')}>
<Text>
Hello.
</Text>
</TouchableOpacity>
</View>
);
}
}
我做错了什么?
提前致谢。
根据 the React Native docs,您需要使用 this.props.navigation
导航,而不是 this.props.navigator
:
export default class Login extends Component{
constructor(props){
super(props);
}
_navigate(routeName){
this.props.navigation({
name: routeName
});
}
render(){
return(
<View style = {styles.container}>
<TouchableOpacity onPress={this._navigate.bind(this, 'Home')}>
<Text>
Hello.
</Text>
</TouchableOpacity>
</View>
);
}
}
class HomeScreen extends React.Component {
//Some code here
}
class ChatScreen extends React.Component {
//Some code here
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
AppRegistry.registerComponent('HelloWorld', () => SimpleApp);
您应该注册 "Simple" 而不是 "HomeScreen"