【问题标题】:undefined is not an object( evaluating ''_this.props.navigator.push")undefined 不是对象(评估 ''_this.props.navigator.push")
【发布时间】:2017-03-24 10:19:44
【问题描述】:

当用户登录时,我试图导航到其他页面。但我收到了这个错误,我似乎无法弄清楚为什么。我正在使用在 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();

  }
}

【问题讨论】:

  • 需要您的组件初始详细信息
  • like as 路由器>
  • 它已经在那里了。我需要在代码中添加一些内容或更改吗?

标签: react-native react-native-router-flux react-native-navigation


【解决方案1】:

你能用导航到其他页面吗

动作.()

前:

Actions.dashboard();

如果传递任何数据

Actions.dashboard({id: 'Ideas'});

import React, { Component } from 'react';

从 'react-native' 导入 {AppRegistry,View,Text,Image, StyleSheet,Navigator, AsyncStorage }; 进口 { 容器, 列表, 项目清单, 内容, 页脚, 页脚标签, 标题, 按钮, 图标, 标签, 标题, 输入组, 输入 } 来自“原生基地”; 进口{ 行动, 场景, 路由器 }来自'react-native-router-flux'; 从 './Reg' 导入 Reg 导出默认类日志扩展组件{ 使成为(){ 返回(

  <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();

} }

【讨论】:

  • 对不起,我不明白。
猜你喜欢
  • 2015-07-16
  • 2020-07-16
  • 2018-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多