react-url-query icon indicating copy to clipboard operation
react-url-query copied to clipboard

document how to link to page

Open rubycut opened this issue 8 years ago • 2 comments

Hi, I would like to use your library, but I can't find any way to create link to my page that supports react-url-query.

In your examples, you explain how to manipulate query string once you are already on desired page, but react apps usually consist of several pages within react-router.

Currently, I am using something like this to switch to another page:

import { withRouter } from 'react-router'
...
this.props.history.push("/cust/" + this.props.customer_id)
...
const ComponentWithRouter = withRouter(Component)
export default connect(mapStateToProps)(ComponentWithRouter)

/cust/ page would support react-url-query, and I would like to jump to this page.

rubycut avatar Dec 05 '17 10:12 rubycut

So if I'm understanding you correctly, you're using React Router and you want to programmatically navigate to a different page (instead of using a Link). If you need to populate URL query parameters for the page to navigate to, you just need to construct the full URL and pass it to history. e.g.:

this.props.history.push('/cust/123?some=88&foo=bar');

react-url-query will then interpret the query parameters for you like you expect.

You can use the Serialize helpers and the subquery and subqueryOmit helpers to construct the query parameters and the query-string library to build the query string itself.

pbeshai avatar Dec 05 '17 15:12 pbeshai

I used something like this:

 let location = JSON.parse(JSON.stringify(window.location));
 location.pathname = "/cust/" + this.props.customer_id
 pushInUrlQuery('server', encode(UrlQueryParamTypes.array, selectedNamesArrray()), location)

rubycut avatar Dec 06 '17 11:12 rubycut