Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix history listener #476

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ConnectedRouter.js
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
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