我使用这样的路由器:
render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="/detail/:blogId" component={DetailView}/>
</Route>
</Router>
), document.getElementById('app'))
在 blog.js
中我使用 Link
<Link to={{ pathname: "/detail", query: { blogId: this.props.id } }}>Detail</Link>
但是没用,如何把:blogId
部分换成state或者props?
最佳答案
:blogId
是参数,不是查询。
您可以像这样简单地在链接标签中设置您的参数:
<Link to={'/detail/' + this.props.id}>Detail</Link>
关于javascript - 如何在 react-router 的链接中引用状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35811266/