React路由器不接受组件作为prop

时间:2016-08-22 22:43:15

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

我正在使用下面显示的应用文件和主要组件关注react redux tutorial,但我收到错误“无效道具component提供给IndexRoute。在IndexRoute”和{{1 }}

Uncaught TypeError: Cannot read property 'props' of undefined

我读到它可能与cloneComponent有关,并试图用//app file import React from 'react'; import { render } from 'react-dom'; // Import Components import Main from './components/Main'; import Single from './components/Single'; import PhotoGrid from './components/PhotoGrid'; // import react router deps import { Router, Route, IndexRoute, browserHistory } from 'react-router'; const router = ( <Router history={browserHistory}> <Route path="/" component={Main}> <IndexRoute component={PhotoGrid}></IndexRoute> <Route path="/view/:postId" component={Single}></Route> </Route> </Router> ) render(router, document.getElementById('root')); 替换该部分,但无济于事。

{React.cloneElement(this.props.children, {...this.props})}

1 个答案:

答案 0 :(得分:0)

您展示的代码没有任何问题。根据错误消息,您的PhotoGrid组件存在问题。由于您未正确呈现PhotoGrid组件,因此react-router不会PhotoGrid作为React组件。检查您的PhotoGrid文件。要确保,只需复制并粘贴源代码即可。