qhistory
Add query object support to history
library location objects.
You will need to supply stringify
and parse
methods.
stringify
A function that takes a query object and returns a search string.
// 'occupation=computer'
parse
A function that takes a search string and returns a query object.
// { stopDownloading: 'true' }
There are lots of different query string packages that you can choose from. Some popular ones include:
There may be subtle differences in the way that each parses and stringifies, so you will need to determine which supports the features that you want.
Installation
npm install --save qhistory
Usage
const history =
Usage with React Router
This can be used with React Router v4 to add query string support to location objects. If a location object has both a search string and a query object, the search string's value will be overwritten by the stringified query object.
const history =
If you're using React Router 4's BrowserRouter you can incorporate qhistory like this:
Component static propTypes = basename: PropTypesstring forceRefresh: PropTypesbool getUserConfirmation: PropTypesfunc keyLength: PropTypesnumber children: PropTypesnode stringify: PropTypesfunc parse: PropTypesfunc history = { return <Router history=thishistory children=thispropschildren /> } // usage