0
나는 유성과 로그 아웃 기능 일하고
/반응 I 오류사용 createContainer와 withRouter 및 사용 내역
Exception in delivering result of invoking 'login': TypeError: Cannot read property 'history' of undefined
at Object.handleLogout (http://localhost:3000/app/app.js?hash=e7e6866f8eccc90d612186214db7d5c0717e09d5:843:38)
at PrivateHeader (http://localhost:3000/app/app.js?hash=e7e6866f8eccc90d612186214db7d5c0717e09d5:828:26)
at http://localhost:3000/packages/modules.js?hash=4b565562fa4100dc773fad2b7836f486fe1cb6aa:11904:16
을 얻고 나는이 문제를 해결하는 방법을 잘 모르겠습니다 그러나
import React from 'react';
import { Accounts } from 'meteor/accounts-base';
import createHistory from 'history/createBrowserHistory';
import propTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
import { createContainer } from 'meteor/react-meteor-data';
const PrivateHeader = (props) => {
return (
<div className="header">
<div className="header__content">
<h1 className="header__title">{props.title}</h1>
<button className="button button--link-text" onClick={ props.handleLogout() }>Logout</button>
</div>
</div>
);
};
PrivateHeader.propTypes = {
title: propTypes.string.isRequired,
handleLogout: propTypes.func.isRequired
};
export default withRouter(createContainer(() => {
return {
handleLogout:() => {
Accounts.logout(),
this.props.history.push('/')
}
};
}, PrivateHeader));
오류. const history = createHistory()를 사용해 보았습니다. 내가 사용하고
종속성은 다음과 같습니다
"dependencies": {
"babel-runtime": "^6.20.0",
"history": "^4.7.2",
"meteor-node-stubs": "~0.2.4",
"moment": "^2.18.1",
"prop-types": "^15.5.10",
"react": "^15.6.2",
"react-addons-pure-render-mixin": "^15.6.2",
"react-dom": "^15.6.1",
"react-router": "^4.1.2",
"react-router-dom": "^4.1.2",
"simpl-schema": "^0.3.2"
},
나는 지금이 정의되지 않은 오류로 밀어 수 없습니다 얻고있다. – user8768174
@ user8768174 코드를 제대로 실행 하시겠습니까? 'this.props.history.push ('/')'를 삭제 했습니까? 'browserHistory'를 올바르게 임포트한다면 그 에러를 얻을 수 없습니다. 오류는 당신이 정의되지 않은 무언가에 대해'push' 메서드를 호출하려고한다는 것을 알려줍니다. –
마침내 알아 낸 바에 따르면 소포를 createContainer에 전달해야했습니다. – user8768174