withRouter of react-router not working&给出错误

时间:2017-11-07 05:45:09

标签: reactjs redux react-router react-router-redux

我创建了一个登录表单&从以下操作成功登录后,将用户重定向到帐户页面:dispatch(push('/account')),因此它更改了URL,但组件未呈现。因此,根据包含withRouter的文档修复此问题,但正如我所说,我得到了一些错误,如:

ERROR in [at-loader] ./src/components/Login/index.tsx:94:27
    TS2345: Argument of type 'ComponentClass<Pick<LoginProps, never>> & { WrappedComponent: ComponentType<LoginProps>; }' is not assignable to parameter of type 'ComponentConstructor<Pick<LoginProps, never> & WithRouterProps>'.
  Type 'ComponentClass<Pick<LoginProps, never>> & { WrappedComponent: ComponentType<LoginProps>; }' is not assignable to type 'StatelessComponent<Pick<LoginProps, never> & WithRouterProps>'.
    Type 'ComponentClass<Pick<LoginProps, never>> & { WrappedComponent: ComponentType<LoginProps>; }' provides no match for the signature '(props: Pick<LoginProps, never> & WithRouterProps & { children?: ReactNode; }, context?: any): ReactElement<any>'.

这是我的登录组件:

import * as React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';

import { emailChanged, passwordChanged, loginUser } from '../../actions';

import { Spinner, Input } from '../../common';

import LoginProps from './interface';
import mapStateToProps from './mapToProps';

class LoginForm extends React.Component<LoginProps, any> {
    onEmailChange(event: any) {
        this.props.emailChanged(event.target.value);
    }

    onPasswordChange(event: any) {
        this.props.passwordChanged(event.target.value);
    }

    onButtonPress() {
        const { email, password } = this.props;

        this.props.loginUser({ email, password });
    }

    render() {
        return (
            <div className="login-container">
            </div>
        )
    }
}

export default withRouter(connect(mapStateToProps, {
    emailChanged, passwordChanged, loginUser
})(LoginForm));

Versions:
"react-redux": "^5.0.2",
"react-router": "^3.0.2",
"react-router-redux": "^4.0.7"

0 个答案:

没有答案