使用redux-react with react-router时,prop'component'无效

时间:2016-07-13 12:37:58

标签: javascript reactjs react-router react-redux

在我的情况下使用来自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)

1 个答案:

答案 0 :(得分:4)

现在var Main包含完整模块。

要访问组件,您需要

var Main = require('./components/Main').default;

import Main from './components/Main';

获取组件。