When navigating directly to a subroute (first load of an app), state.location is null.
However, on navigating to a url in the app, the location is filled correctly:

Is there a way to push this on page load ?
I've temporarily solved this by updating store/location.js to include the following, but hopefully there's a more "correct" way:
BEFORE:
const initialState = null
AFTER
```
const getParams = query => {
if (!query) {
return { }
}
return (/^[?#]/.test(query) ? query.slice(1) : query)
.split('&')
.reduce((params, param) => {
let [ key, value ] = param.split('=')
params[key] = value ? decodeURIComponent(value.replace(/+/g, ' ')) : ''
return params
}, { })
}
// ------------------------------------
// Reducer
// ------------------------------------
const initialState = {
pathname: window.location.pathname,
search: window.location.search,
hash: window.location.hash,
action: null,
key: null,
query: getParams(window.location.search)
}
````
I am importing browserHistory in location.js and setting initialState like so:
// ------------------------------------
// Reducer
// ------------------------------------
const initialState = browserHistory.getCurrentLocation()
export default function locationReducer (state = initialState, action) {
return action.type === LOCATION_CHANGE
? action.payload
: state
}
@code-press - Yup, that works well.
Thanks!
Created a PR with the change - https://github.com/davezuko/react-redux-starter-kit/pull/1149
Fixed with your PR, thank you.
Most helpful comment
Created a PR with the change - https://github.com/davezuko/react-redux-starter-kit/pull/1149