Reactjs 如何在react路由器中添加查询

Reactjs 如何在react路由器中添加查询,reactjs,routes,react-router,Reactjs,Routes,React Router,这是现在 http://localhost:8001/components/button/ 我想 http://localhost:8001/components/button/?theme=dark 我曾经 browserHistory.push({ pathname: '', query: {theme: dark}, }) and browserHistory.push({ pathname: 'components/button', query: {theme: da

这是现在

http://localhost:8001/components/button/

我想

http://localhost:8001/components/button/?theme=dark

我曾经

browserHistory.push({
  pathname: '',
  query: {theme: dark},
})

and

browserHistory.push({
  pathname: 'components/button',
  query: {theme: dark},
})

and 

browserHistory.push({
  pathname: 'button',
  query: {theme: dark},
})
全部失败。


我该怎么办?你能帮我吗,谢谢

您可以只使用
字符串文本
,然后进入历史记录

browserHistory.push(`components/button?theme=${dark}`)

您可以使用
push
方法:

browserHistory.push({
  pathname: '/components/button',
  search: '?theme=dark'
})
或者简单地说:

browserHistory.push('/components/button?theme=dark')

我用过。它与“路径名:'components/button'”相同,`结果是它将是/components/button/components/button/?theme=dark这是/components/button/,而不是/components/button。所以它不起作用。你不能只做
browserHistory.push(“/components/button/?theme=dark”)
或尝试
browserHistory.push({pathname:'components/button',search:'theme:dark',})
@dikuw结果是localhost:8001/components/button/components/button/button/?theme=dark