的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'路由的其他途径也没有什么关系,但是除去其他路线,并重新尝试之后,事情的来龙去脉。要排除故障并查看哪条路线明确导致问题。 –