xrkffgg
xrkffgg

Reputation: 1

how can i add query in react router

this is now

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

I want to

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

I used

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

and

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

and 

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

All failed.

How can i do? Can you help me, thank you!

Upvotes: 0

Views: 71

Answers (2)

shahidiqbal
shahidiqbal

Reputation: 385

You can use the push method as:

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

or simple as:

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

Upvotes: 0

Prateek Thapa
Prateek Thapa

Reputation: 4938

You could just use a string literal and push onto history.

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

Upvotes: 1

Related Questions