Skip to content

Commit

Permalink
fix history listener
Browse files Browse the repository at this point in the history
  • Loading branch information
kale1d0code committed Feb 1, 2021
1 parent a105380 commit 441dad3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/ConnectedRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const createConnectedRouter = (structure) => {
}
})

const handleLocationChange = (location, action, isFirstRendering = false) => {
const handleLocationChange = ({location, action}, isFirstRendering = false) => {
// Dispatch onLocationChanged except when we're in time travelling
if (!this.inTimeTravelling) {
onLocationChanged(location, action, isFirstRendering)
onLocationChanged({location, action}, isFirstRendering)
} else {
this.inTimeTravelling = false
}
Expand All @@ -75,7 +75,7 @@ const createConnectedRouter = (structure) => {
// Dispatch a location change action for the initial location.
// This makes it backward-compatible with react-router-redux.
// But, we add `isFirstRendering` to `true` to prevent double-rendering.
handleLocationChange(history.location, history.action, true)
handleLocationChange({location, action} = history, true)
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ const createConnectedRouter = (structure) => {
}

const mapDispatchToProps = dispatch => ({
onLocationChanged: (location, action, isFirstRendering) => dispatch(onLocationChanged(location, action, isFirstRendering))
onLocationChanged: ({location, action}, isFirstRendering) => dispatch(onLocationChanged({location, action}, isFirstRendering))
})

const ConnectedRouterWithContext = props => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE'

export const onLocationChanged = (location, action, isFirstRendering = false) => ({
export const onLocationChanged = ({location, action}, isFirstRendering = false) => ({
type: LOCATION_CHANGE,
payload: {
location,
Expand Down

0 comments on commit 441dad3

Please sign in to comment.