【问题标题】:how to pass the data from one page to another in react.js and using reach router如何在 react.js 中将数据从一个页面传递到另一个页面并使用到达路由器
【发布时间】:2021-10-20 11:37:34
【问题描述】:

我想在第二个页面上使用一些数据,我正在使用到达路由器链接路由到该页面,有什么方法可以这样做吗?

【问题讨论】:

    标签: reactjs reach-router


    【解决方案1】:

    我们在使用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]

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 1970-01-01
      • 2018-04-10
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2015-09-12
      相关资源
      最近更新 更多