我正在使用下面显示的应用文件和主要组件关注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})}
答案 0 :(得分:0)
您展示的代码没有任何问题。根据错误消息,您的PhotoGrid
组件存在问题。由于您未正确呈现PhotoGrid
组件,因此react-router
不会PhotoGrid
作为React组件。检查您的PhotoGrid
文件。要确保,只需复制并粘贴源代码即可。