gpt4 book ai didi

reactjs - react 路由器不渲染组件

转载 作者:行者123 更新时间:2023-12-03 13:51:39 25 4
gpt4 key购买 nike

我使用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>

关于reactjs - react 路由器不渲染组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38236156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com