From d9f83d1fe3b81708760b1c2ce39461ca532bc586 Mon Sep 17 00:00:00 2001 From: James Gillmore Date: Thu, 27 Jul 2017 22:28:37 -0700 Subject: [PATCH] fix($queryStringDocs): add note about querySerializer and example actions --- docs/query-strings.md | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/query-strings.md b/docs/query-strings.md index c54b1724..3a42853e 100644 --- a/docs/query-strings.md +++ b/docs/query-strings.md @@ -23,6 +23,35 @@ The `` component--if you supply a string for the `to` prop--will put it The actual search string will only ever exist at: - `action.meta.location.current.search` +## Some Example Actions + +Using links, here is some examples of how to format these actions: + +*action.query:* +```js + +``` + +*action.payload.query:* +```js + +``` + +*action.meta.query:* +```js + +``` + +The matching route would be: + +```js +const routesMap = { + ANYTHING: '/anything/:key' +} +``` + +Notice there is no path params for query key/vals. They don't affect the determination of which route is selected. Only the `type` and `payload` do. The same `type` is shared no matter what query is provided.. + ## Where will `query` + `search` live in `location` state? @@ -33,6 +62,23 @@ store.getState().location.query store.getState().location.search ``` + +## How to Enable Query String Serialization + +To enable query string serialization you must provide a `querySerializer` option to `connectRoutes` like this: + +```js +import queryString from 'query-string' + +connectRoutes(routesMap, { + querySerializer: queryString +}) +``` +If you would like to create your own, you can pass any object with a `stringify` and `parse` function. The former takes an object and creates a query string and the latter takes a `string` and creates an object. + +Also note that the `query-string` package will produce strings for numbers. There's a [package](https://github.com/mariusc23/express-query-int) made for express that will format numbers into `ints`, which you may be interested in learning from if you want to achieve that goal. I couldn't find a general one identical to this one. If you make it, publish it to NPM and make a PR to this doc with a link to it. *I think it's a mistake that numbers aren't converted for you.* + + ## CodeSandBox You can test out query support on codesandbox here: