反应:TypeError:无法读取未定义的属性“ push”

时间:2018-09-20 16:12:46

标签: reactjs firebase react-router

我将Firebase实施到我的React Project。当用户注册时,我想将他们重定向到主页。为此,我尝试使用history.push()。但是当我使用它时,控制台中总是出现以下错误:

TypeError: Cannot read property 'push' of undefined

这是我的“注册”对话框:

import React, { Component } from 'react';
import { withRouter, history } from 'react-router-dom';
import Box from 'ui-box';
import SignUpForm from './SignUpForm';
import { Dialog, Heading, IconButton, Pane} from 'evergreen-ui';

class SignUpDialog extends Component {

  render() {
    return (
      <Dialog
        isShown={this.props.showLogin}
        title="Login"
        hasHeader={false}
        hasFooter={false}
        width={440}
      >
        {({ close, history }) => (
          <Box>
            <Pane
              flexShrink={0}
              paddingLeft={15}
              paddingRight={15}
              paddingBottom={15}
              display="flex"
              alignItems="center"
            >
              <Heading size={600} flex={1}>
                Create a new Account
              </Heading>
              <IconButton
                appearance="minimal"
                icon="cross"
                onClick={close}
                className
              />
            </Pane>   
            <SignUpForm onCancel={close} history={history}/>
          </Box>
        )}
      </Dialog>
    );
  }
}

export default withRouter(SignUpDialog);

这是我在SignUpForm Compoment中的handleSubmit()函数,用于使用SignUpDialog中的历史记录道具:

//SignUpForm Component
handleSubmit() {
    const {
      history,
    } = this.props;
    if (this.checkFormStatus()) {
      auth.doCreateUserWithEmailAndPassword(this.state.email, this.state.email).then(authUser => {
        this.setState({
          email:"",
          password:"",
        });
        history.push(routes.Home)
      }).catch(error => {
        console.log(error)
      });
    }
  }

我的问题在哪里?请帮助我...谢谢您的回答

0 个答案:

没有答案