如何使用反应路由器在重定向上传递参数? [英] How can i pass parameters on redirection using react router?
问题描述
我正在使用react路由器版本2.0.1进行组件之间的导航。我遇到了一个场景,我想动态导航到其他组件
我做了类似这样的重定向
I'm using react router version 2.0.1 for navigation between components. I came across a scenario where i want dynamically navigate to other component I did something like this for redirection
browserHistory.push("/some/path");
它完美地导航到其他组件。但我也想传递一些参数和重定向。
我试过这样做
It is navigating to other component perfectly. But i also want to pass some parameters along with the redirection. I tried doing it like
browserHistory.push("/some/path", {query: "param1"});
browserHistory.push("/some/path", {query: {param1: value1}});
但是当我尝试从中获取值时this.props.location
它显示空白查询结果。
But when i try to fetch the value from this.props.location
it shows blank query result.
任何建议都将不胜感激。
Any suggestions would be greatly appreciated.
推荐答案
这项工作适合你:
router.push({
pathname: '/some/path',
query: { param1: value1 }
})
或者我看过有人这样做,看起来好像正常工作:
or I've seen people doing this and looks like its workin ok:
browserHistory.push("/some/path?param1=value1");
这篇关于如何使用反应路由器在重定向上传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!