的this.props.children而不是我試圖從反應路由器0.13升級到1.0。我仔細閱讀本指南,我相信我擁有了一切設置正確,但我不斷收到此錯誤:反應路由器1.0:使用RouteHandler
Uncaught TypeError: Cannot read property 'createRouteFromReactElement' of undefined
的錯誤對應於反應路由器此功能:
function createRoutesFromReactChildren(children, parentRoute) {
var routes = [];
_react2['default'].Children.forEach(children, function (element) {
if (_react2['default'].isValidElement(element)) {
// Component classes may have a static create* method.
if (element.type.createRouteFromReactElement) {
var route = element.type.createRouteFromReactElement(element, parentRoute);
if (route) routes.push(route);
} else {
routes.push(createRouteFromReactElement(element));
}
}
});
return routes;
}
據推測,這意味着,路線沒有得到通過爲this.props.children
是否正確?
如果有幫助,這裏是我的路線是這樣的:
var routes = (
<Route path="/" component={AppView}>
<Route path="account" component={Account} />
<Route path="insights" component={InsightsHome} />
<Route path="insights/:slug" component={SingleInsight} />
<Route path="collections" component={CollectionBox}>
<Route path="/:id" component={CollectionContent} />
<DefaultRoute component={NoCollections} />
</Route>
<Route path="team" component={Team} />
<Redirect from="projects/:projectId/insights/?" to="insights" />
<Redirect from="projects/:projectId/insights/:slug/?" to="insights-single" />
<Redirect from="*" to="insights" />
</Route>
);
這裏是我的render
方法(我用的終極版):
ReactDOM.render(
<Provider store={store}>
<Router history={history}>{routes}</Router>
</Provider>,
document.getElementById('site-container')
);
而且這裏是有關這塊我AppView
組件:
return (
<div>
{this.props.children}
</div>
)
},
ING代替你已經嘗試將它縮小,看看是否只有那些路線的一個原因? – enjoylife
良好的通話mattclemens。我是假設,因爲我打了'insights'路由的其他途徑也沒有什麼關係,但是除去其他路線,並重新嘗試之後,事情的來龍去脈。要排除故障並查看哪條路線明確導致問題。 –