undefined 不是对象(评估 ''_this.props.navigator.push")
undefined is not an object( evaluating ''_this.props.navigator.push")
我正在尝试在用户登录时导航到其他页面。但是我收到了这个错误,我似乎无法弄清楚为什么。我正在使用 mac。
我也尝试使用 navigatorIOS,但问题不会消失。请帮忙
import React, { Component } from 'react';
import {AppRegistry,View,Text,Image, StyleSheet,Navigator, AsyncStorage } from 'react-native';
import {
Container,
List,
ListItem,
Content,
Footer,
FooterTab,
Header,
Button,
Icon,
Tabs,
Title,
InputGroup,
Input
} from 'native-base';
import{
Actions,
Scene,
Router
}from 'react-native-router-flux';
import Reg from './Reg'
export default class Log extends Component{
render(){
return(
<Container>
<View style={{alignItems:'center'}}>
<Icon name='ios-contact' style={{fontSize:120}}/>
</View>
<Content style={{flex:1, top:50}}>
<List>
<ListItem>
<InputGroup>
<Icon name='ios-at-outline' style={{color:'#5bc0de'}}/>
<Input
onChangeText={(username) => this.setState({username})}
value={this.state.username} placeholder='Email id' />
</InputGroup>
</ListItem>
<ListItem>
<InputGroup>
<Icon name='ios-lock-outline' style={{color:'#5bc0de'}}/>
<Input onChangeText={(password) => this.setState({password})}
value={this.state.password} placeholder="Password" secureTextEntry />
</InputGroup>
</ListItem>
<Button info style={{alignSelf:'center'}} onPress={this.Log}>
LOGIN
</Button>
</List>
</Content>
</Container>
);
}
constructor(props){
super(props);
this.state = {username: '', password: ''};
console.log();
}
Log = () => {
fetch('http://192.168.0.20:3000/users', {
method : 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if(res.success=== true){
var username = res.message;
AsyncStorage.setItem('username', username);
this.props.navigator.push({
id: 'Ideas'
});
}else {
alert(res.message);
}
})
.done();
}
}
你可以使用导航到其他页面吗
动作.()
EX:
Actions.dashboard();
如果传递任何数据
Actions.dashboard({id: 'Ideas'});
import React, { Component } from 'react';
从 'react-native' 导入 {AppRegistry、View、Text、Image、StyleSheet、Navigator、AsyncStorage};
进口 {
容器,
列表,
项目清单,
内容,
页脚,
页脚标签,
Header,
按钮,
图标,
标签,
标题,
输入组,
输入
} 来自 'native-base';
进口{
行动,
场景,
路由器
}来自 'react-native-router-flux';
从 './Reg' 导入 Reg
export default class Log extends Component{
使成为(){
return(
<Container>
<View style={{alignItems:'center'}}>
<Icon name='ios-contact' style={{fontSize:120}}/>
</View>
<Content style={{flex:1, top:50}}>
<List>
<ListItem>
<InputGroup>
<Icon name='ios-at-outline' style={{color:'#5bc0de'}}/>
<Input
onChangeText={(username) => this.setState({username})}
value={this.state.username} placeholder='Email id' />
</InputGroup>
</ListItem>
<ListItem>
<InputGroup>
<Icon name='ios-lock-outline' style={{color:'#5bc0de'}}/>
<Input onChangeText={(password) => this.setState({password})}
value={this.state.password} placeholder="Password" secureTextEntry />
</InputGroup>
</ListItem>
<Button info style={{alignSelf:'center'}} onPress={this.Log}>
LOGIN
</Button>
</List>
</Content>
</Container>
);
}
constructor(props){
super(props);
this.state = {username: '', password: ''};
console.log();
}
Log = () => {
fetch('http://192.168.0.20:3000/users', {
method : 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if(res.success=== true){
var username = res.message;
AsyncStorage.setItem('username', username);
this.props.navigator.push({ // Remove this line
id: 'Ideas' // Remove this line
}); // Remove this line
Actions.<pushComponentName>({id: 'Ideas'}) // Add this line
}else {
alert(res.message);
}
})
.done();
}
}
我正在尝试在用户登录时导航到其他页面。但是我收到了这个错误,我似乎无法弄清楚为什么。我正在使用 mac。 我也尝试使用 navigatorIOS,但问题不会消失。请帮忙
import React, { Component } from 'react';
import {AppRegistry,View,Text,Image, StyleSheet,Navigator, AsyncStorage } from 'react-native';
import {
Container,
List,
ListItem,
Content,
Footer,
FooterTab,
Header,
Button,
Icon,
Tabs,
Title,
InputGroup,
Input
} from 'native-base';
import{
Actions,
Scene,
Router
}from 'react-native-router-flux';
import Reg from './Reg'
export default class Log extends Component{
render(){
return(
<Container>
<View style={{alignItems:'center'}}>
<Icon name='ios-contact' style={{fontSize:120}}/>
</View>
<Content style={{flex:1, top:50}}>
<List>
<ListItem>
<InputGroup>
<Icon name='ios-at-outline' style={{color:'#5bc0de'}}/>
<Input
onChangeText={(username) => this.setState({username})}
value={this.state.username} placeholder='Email id' />
</InputGroup>
</ListItem>
<ListItem>
<InputGroup>
<Icon name='ios-lock-outline' style={{color:'#5bc0de'}}/>
<Input onChangeText={(password) => this.setState({password})}
value={this.state.password} placeholder="Password" secureTextEntry />
</InputGroup>
</ListItem>
<Button info style={{alignSelf:'center'}} onPress={this.Log}>
LOGIN
</Button>
</List>
</Content>
</Container>
);
}
constructor(props){
super(props);
this.state = {username: '', password: ''};
console.log();
}
Log = () => {
fetch('http://192.168.0.20:3000/users', {
method : 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if(res.success=== true){
var username = res.message;
AsyncStorage.setItem('username', username);
this.props.navigator.push({
id: 'Ideas'
});
}else {
alert(res.message);
}
})
.done();
}
}
你可以使用导航到其他页面吗
动作.()
EX:
Actions.dashboard();
如果传递任何数据
Actions.dashboard({id: 'Ideas'});
import React, { Component } from 'react';
从 'react-native' 导入 {AppRegistry、View、Text、Image、StyleSheet、Navigator、AsyncStorage}; 进口 { 容器, 列表, 项目清单, 内容, 页脚, 页脚标签, Header, 按钮, 图标, 标签, 标题, 输入组, 输入 } 来自 'native-base'; 进口{ 行动, 场景, 路由器 }来自 'react-native-router-flux'; 从 './Reg' 导入 Reg export default class Log extends Component{ 使成为(){ return(
<Container>
<View style={{alignItems:'center'}}>
<Icon name='ios-contact' style={{fontSize:120}}/>
</View>
<Content style={{flex:1, top:50}}>
<List>
<ListItem>
<InputGroup>
<Icon name='ios-at-outline' style={{color:'#5bc0de'}}/>
<Input
onChangeText={(username) => this.setState({username})}
value={this.state.username} placeholder='Email id' />
</InputGroup>
</ListItem>
<ListItem>
<InputGroup>
<Icon name='ios-lock-outline' style={{color:'#5bc0de'}}/>
<Input onChangeText={(password) => this.setState({password})}
value={this.state.password} placeholder="Password" secureTextEntry />
</InputGroup>
</ListItem>
<Button info style={{alignSelf:'center'}} onPress={this.Log}>
LOGIN
</Button>
</List>
</Content>
</Container>
);
}
constructor(props){
super(props);
this.state = {username: '', password: ''};
console.log();
}
Log = () => {
fetch('http://192.168.0.20:3000/users', {
method : 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if(res.success=== true){
var username = res.message;
AsyncStorage.setItem('username', username);
this.props.navigator.push({ // Remove this line
id: 'Ideas' // Remove this line
}); // Remove this line
Actions.<pushComponentName>({id: 'Ideas'}) // Add this line
}else {
alert(res.message);
}
})
.done();
} }