使用反应路由器获取散列之前的查询参数?
Get query param that comes before the hash with react router?
我正在使用 React router 1.0.0,我不知道是否可以将散列之前的查询参数获取到我的应用程序中。这是我在本地 运行 我的应用程序时 url 的示例:
http://127.0.0.1:8001/community/wkO_lhA_RnOMDeTA3kDgpA/calendar?coordinator=1#/cal/view/month
我想要得到的是 "coordinator=1" 参数。到目前为止,我所看到的关于 react router 中的参数的所有信息都是在散列之后获取参数,因此在 URL 的 /cal/view/month 部分,而不是在散列之前。
有人有什么想法吗?
this.props.location.query
就是你想要的。在您的情况下,该值是 { coordinator:1 }
例如http://localhost:5000/users/2?q=hello#meow。 React-router 为该路由加载 User
组件,并将 history、location、params、route、routeParams、routes 作为 props 传递给它。 Chrome.
的 React-Devtools 截图
我正在使用 React router 1.0.0,我不知道是否可以将散列之前的查询参数获取到我的应用程序中。这是我在本地 运行 我的应用程序时 url 的示例:
http://127.0.0.1:8001/community/wkO_lhA_RnOMDeTA3kDgpA/calendar?coordinator=1#/cal/view/month
我想要得到的是 "coordinator=1" 参数。到目前为止,我所看到的关于 react router 中的参数的所有信息都是在散列之后获取参数,因此在 URL 的 /cal/view/month 部分,而不是在散列之前。
有人有什么想法吗?
this.props.location.query
就是你想要的。在您的情况下,该值是 { coordinator:1 }
例如http://localhost:5000/users/2?q=hello#meow。 React-router 为该路由加载 User
组件,并将 history、location、params、route、routeParams、routes 作为 props 传递给它。 Chrome.