在我的情况下使用来自react-redux的connect
反应路由器没有看到我的反应组件作为有效组件。并且有一个警告:失败的propType:提供给component
的无效道具Route
index.js
import { connect } from 'react-redux'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import plattformApp from './reducers'
var React = require('react');
var ReactDOM = require('react-dom');
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var hashHistory = ReactRouter.hashHistory;
var Main = require('./components/Main');
let store = createStore(plattformApp)
ReactDOM.render(
<Provider store={store}>
<Router history={hashHistory}>
<Route path='/' component={Main}>
</Route>
</Router>
</Provider>,
document.getElementById('app')
)
Main.js
var React = require('react');
var ReactRouter = require('react-router');
var Link = ReactRouter.Link;
var KNGui = require("../components/KNGui");
var Search = require("../components/Search");
var Main = React.createClass({
render: function () {
return (
<div>
</div>
)
}
});
function mapStateToProps(state) {
return { test: state }
}
export default connect(mapStateToProps)(Main)
答案 0 :(得分:4)
现在var Main
包含完整模块。
要访问组件,您需要
var Main = require('./components/Main').default;
或
import Main from './components/Main';
获取组件。