Gets query string parameters from window location substring.
yarn add @patomation/query-param
npm install @patomation/query-param --save
import { queryParam } from '@patomation/query-param'
const myParams = queryParam()
Example url might be:
https://mySite.com/?make=Tesla&model=T&year=2019electric=true
Result is one json object:
// myParams =
{
make: 'Tesla',
model: 'T',
year: 2019,
electric: true
}
You can set a query param with this. It will be persisted in local storage. So when you redirect and go to a different page the param will be present.
import { localStorageQueryParam } from '@patomation/query-param'
const myParams = localStorageQueryParam()
Example:
- navigate to page one with the param
https://mySite.com/pageOne/?cool=beans
// pageOne params =
{
cool: 'beans'
}
- navigate to page two without the query string. The param will still exist in local storage
https://mySite.com/pageTwo/
// pageTwo params =
{
cool: 'beans'
}
The local storage key is 'persist:queryParam'
- white spaces
converts %20 to white space