gpt4 book ai didi

reactjs - React-router 4 不使用查询参数更新 url

转载 作者:行者123 更新时间:2023-12-03 13:31:16 26 4
gpt4 key购买 nike

我使用更高级别的过滤器组件将查询参数添加到 URL,以便用户可以与不同类型的过滤器共享链接。

我正在导出组件withRouter(),一切看起来都是合法的 - 我将历史记录注入(inject)到组件 Prop 中。但是,当我调用这段代码时:

this.props.history.push({
pathname: this.props.history.location.pathname,
query: { tags: selectedTags }
});

它确实改变了 this.props.history 的状态,我可以看到我的查询存在,但浏览器中的 URL 没有改变。我做错了什么吗?

最佳答案

你用错了,你的代码应该是:

this.props.history.push({
pathname: this.props.history.location.pathname,
search: `?tags=${ selectedTags }`
});

您可以阅读有关导航的更多信息:https://github.com/ReactTraining/history#navigation

关于reactjs - React-router 4 不使用查询参数更新 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46484422/

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