你如何以编程方式更新 react-router 中的查询参数? [英] How do you programmatically update query params in react-router?

查看:39
本文介绍了你如何以编程方式更新 react-router 中的查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到如何在不使用 的情况下使用 react-router 更新查询参数.hashHistory.push(url) 似乎没有注册查询参数,而且您似乎不能将查询对象或任何东西作为第二个参数传递.

I can't seem to find how to update query params with react-router without using <Link/>. hashHistory.push(url) doesn't seem to register query params, and it doesn't seem like you can pass a query object or anything as a second argument.

如何在不使用 的情况下在 react-router 中将 url 从 /shop/Clothes/dresses 更改为 /shop/Clothes/dresses?color=blue<链接>?

How do you change the url from /shop/Clothes/dresses to /shop/Clothes/dresses?color=blue in react-router without using <Link>?

onChange 函数真的是监听查询更改的唯一方法吗?为什么不自动检测查询更改并响应参数更改的方式?

And is an onChange function really the only way to listen for query changes? Why aren't query changes automatically detected and reacted-to the way that param changes are?

推荐答案

hashHistorypush 方法中,您可以指定查询参数.例如,

Within the push method of hashHistory, you can specify your query parameters. For instance,

history.push({
  pathname: '/dresses',
  search: '?color=blue'
})

history.push('/dresses?color=blue')

您可以查看此存储库,了解有关使用history的其他示例

You can check out this repository for additional examples on using history

这篇关于你如何以编程方式更新 react-router 中的查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆