反应路由器不渲染组件
问题描述:
我开发我的项目与react-router
。反应路由器不渲染组件
下面是我的代码。
const App2 = React.createClass({
render() {
return (
<div>
<Link to="index">index</Link>
<Link to="favorite">favorite</Link>
<Link to="myPage">myPage</Link>
{this.props.children}
</div>
)
}
});
var app = ReactDOM.render (
<Router history={browserHistory}>
<Route path="/" component={App2}>
<Route path="index" component={PhotoFeedWrapper}/>
<Route path="favorite" component={FavoriteWrapper}/>
<Route path="myPage" component={MyPageWrapper}/>
</Route>
</Router>,
document.getElementById('app')
);
我想我的代码是正确的。但是,如下所示,这呈现为空。
<div id="app"><!-- react-empty: 1 --></div>
没有脚本错误。
我做错了什么?
答
Link
组件当前仅支持绝对路径。您必须更改为:
<Link to="/index">index</Link>
<Link to="/favorite">favorite</Link>
<Link to="/myPage">myPage</Link>
+0
我看到你的'链接'设置,然后我立即发布这个。然后我意识到这并不能回答你原来的问题。但它确实在您的代码中修复了另一个错误。 :P – xiaofan2406
您是如何访问它的?使用'http:// localhost/index'?另外,你可以发布你的其他组件,看看它们是否正确? –
@WilliamMartins不,我访问它'http:// localhost:8080/contextPath/index'。我不在节点上使用它。我用它与春天和UMD构建。所以,我喜欢那样使用。其他组件是正确的 –
这很奇怪,你的链接被渲染? –