【发布时间】:2021-10-20 11:37:34
【问题描述】:
我想在第二个页面上使用一些数据,我正在使用到达路由器链接路由到该页面,有什么方法可以这样做吗?
【问题讨论】:
标签: reactjs reach-router
我想在第二个页面上使用一些数据,我正在使用到达路由器链接路由到该页面,有什么方法可以这样做吗?
【问题讨论】:
标签: reactjs reach-router
我们在使用reach-router时可以这样做
放置位置状态的对象。
第 1 页(导航自):
const NewsFeed = () => (
<div>
<Link
to="photos/123"
state={{ fromFeed: true }}
/>
</div>
)
第 2 页(导航至):
const Photo = ({ location, photoId }) => {
if (location.state.fromFeed) {
return <FromFeedPhoto id={photoId} />
} else {
return <Photo id={photoId} />
}
}
有关更多详细信息,请使用此文档https://reach.tech/router/api/Link[][1]
【讨论】: