0
我下列如下所示的應用程序文件和主要成分的react redux tutorial但我得到的錯誤「提供給IndexRoute
無效丙component
。在IndexRoute」和Uncaught TypeError: Cannot read property 'props' of undefined
。陣營路由器不接受成分作爲丙
//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'));
,我讀了它可能是做的cloneComponent並試圖與{React.cloneElement(this.props.children, {...this.props})}
但無濟於事,以取代部分。
//main
import React from 'react';
import { Link } from 'react-router';
const Main = React.createClass({
render() {
return (
<div>
<h1>
<Link to="/">Reduxstagram</Link>
</h1>
{React.cloneElement(this.props.children, this.props)}
</div>
)
}
});
export default Main;
嘗試使用'{this.props.children}'而不是'{React.cloneElement(this.props.children,this.props)}' – Alejandro