{"action":"opened","issue":{"url":"https://api.github.com/repos/ReactTraining/react-router/issues/3899","repository_url":"https://api.github.com/repos/ReactTraining/react-router","labels_url":"https://api.github.com/repos/ReactTraining/react-router/issues/3899/labels{/name}","comments_url":"https://api.github.com/repos/ReactTraining/react-router/issues/3899/comments","events_url":"https://api.github.com/repos/ReactTraining/react-router/issues/3899/events","html_url":"https://github.com/ReactTraining/react-router/issues/3899","id":177643394,"number":3899,"title":"Make location.query always be an object","user":{"login":"cesarandreu","id":656870,"avatar_url":"https://avatars.githubusercontent.com/u/656870?v=3","gravatar_id":"","url":"https://api.github.com/users/cesarandreu","html_url":"https://github.com/cesarandreu","followers_url":"https://api.github.com/users/cesarandreu/followers","following_url":"https://api.github.com/users/cesarandreu/following{/other_user}","gists_url":"https://api.github.com/users/cesarandreu/gists{/gist_id}","starred_url":"https://api.github.com/users/cesarandreu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cesarandreu/subscriptions","organizations_url":"https://api.github.com/users/cesarandreu/orgs","repos_url":"https://api.github.com/users/cesarandreu/repos","events_url":"https://api.github.com/users/cesarandreu/events{/privacy}","received_events_url":"https://api.github.com/users/cesarandreu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-18T10:11:55Z","updated_at":"2016-09-18T10:11:55Z","closed_at":null,"body":"So far I'm liking v4.  However, this detail stood out to me.\r\n\r\nMaking `location.query` _always_ be an object would save us from having `location.query || {}` all around our code. I can't think of any scenarios in which I'd find a null `location.query` useful. If you wanted to check if there's no query param, you could use `!location.search`.\r\n\r\nHaving `location.query` always be an an object means you don't have to perform the extra conditional check whenever you want to read a value. I think that the common use-case would be to try reading a query param value, and use a default fallback when the the value is missing.\r\n\r\n\r\nSome prior art that shares this behavior:\r\n\r\n* [url.parse](https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost) from node's built-in modules will return an empty object when `parseQueryString` is true (it uses [querystring.parse](https://nodejs.org/api/querystring.html#querystring_querystring_parse_str_sep_eq_options), which always return an object)\r\n* [qs.parse](https://github.com/ljharb/qs#parsing-objects) will always return an empty object\r\n* [req.query](http://expressjs.com/en/4x/api.html#req.query) from express is always an object\r\n* [window.URL](https://developer.mozilla.org/en-US/docs/Web/API/Window/URL) will always set `url.query` to a URLSearchParams object\r\n"}}
{"actor":{"display_login":"cesarandreu"}}