Closed cmolenda closed 4 years ago
Thank you for this great suggestion, @cmolenda. I am open to exposing the full capability of query-string
. Let's work on an API for this.
My initial thought is to allow parse()
and stringify()
to be passed in as options. I would also change the RouterState definition as follows:
class RouterState {
constructor(
readonly routeName: string,
readonly params: {[key: string]: string} = {},
readonly queryParams: {[key: string]: any} = {}
) {}
}
Finally, I would upgrade the query-string
dependency to 6.x.
Please let me know your thoughts.
Excellent work! And very easy to understand spec, too: https://github.com/nareshbhatia/mobx-state-router/commit/61eeb475d490afe8bc70552c4d67000d78185aed#diff-47052a903b896d9f6a8eacf0c7c690acR70 😄
Thank you for this.
Problem Bracket formatted array values in query strings do not return arrays in the
toState
of routesonEnter
callback.Request Allow users to specify which parsing format the query-string library uses
Details When using this module in conjunction with a server framework such as Rails, the server's query string format for array values uses the pattern
keyName[]=value
. E.g. for users1,2,3
, the query string is?users[]=1&users[]=2&users[]=3
.The query-string library used in the HistoryRouter and StaticRouter has this capability, but it does not look like it is exposed.
Since the library's default query mechanism is being used, the
toState
for anonEnter
hook for the string?status=enabled&userIds[]=1&userIds[]=2&userIds[]=3
results in the object{ status: "enabled", users[]: 3 }
Example routes.js
Current Workaround Use the global window location.