0

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

  }
}
4

1 回答 1

0

您可以使用导航到其他页面吗

行动。()

前任:

Actions.dashboard();

如果传递任何数据

Actions.dashboard({id: '想法'});

import React, { Component } from 'react';

从 'react-native' 导入 {AppRegistry,View,Text,Image, StyleSheet,Navigator, AsyncStorage };import { Container, List, ListItem, Content, Footer, FooterTab, Header, Button, Icon, Tabs, Title, InputGroup, Input } from 'native-base'; 从'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({  // Remove this line
                   id: 'Ideas'                // Remove this line
                 });                          // Remove this line
                 Actions.<pushComponentName>({id: 'Ideas'})  // Add this line
            }else {
                alert(res.message);
            }



    })

    .done();

} }

于 2017-03-24T10:32:12.360 回答