gpt4 book ai didi

react-router - React Router 的 组件中的状态是什么?

转载 作者:行者123 更新时间:2023-12-04 04:45:17 25 4
gpt4 key购买 nike

这是他们关于 <Link> 的文档的截图component

enter image description here

  • 什么 state他们是什么意思?一个 Redux状态?
  • 通过状态看起来如何?像这样?
        pathname: '/foo',
    query: {
    x: this.props.x,
    },
    state: store.getState()
  • 最佳答案

    这是您想要发送到下一页的信息。与 Redux 无关。这是一个简单的对象。我相信 Flipkart 是一个很好的例子,说明如何使用它来改善用户体验:

  • 转至 Flipkart search page在移动设备上(或使用 Chrome DevTools 模拟)
  • 点击其中一项

  • 您会看到转换立即发生,产品图片、标题、评级和价格等信息在产品页面上随时可用。一种实现方法是将他们已经在搜索页面上加载的状态传递到下一个页面:
    <Link
    to={`/product/${id}`}
    state={{
    product,
    }}
    />
    进而:
    function ProductPage(props) {
    // Always check because state is empty on first visit
    if (props.location.state.product) {
    console.log(props.location.state.product);
    // { id: '...', images: [...], price: { ... } }
    }
    }

    关于react-router - React Router 的 <Link> 组件中的状态是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41736048/

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