Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Last active August 18, 2017 05:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save faceyspacey/e7225d6dae7f8226a3ac6e9d1f718d60 to your computer and use it in GitHub Desktop.
const history = createHistory({
getUserConfirmation(message, callback) {
confirmationDialog(message, (res) => {
shouldChange = !!res
callback(res)
})
}
})
history.block((location, action) => {
const state = selectLocationState(getState())
let action = pathToAction(location.pathname, routesMap)
const route = routesMap[action.type]
if (route) {
action = middlewareCreateAction(
action,
routesMap,
prevLocation,
history,
notFoundPath,
querySerializer
)
const nextState = reducer(state, action)
const res = confirmLeave(state, nextState)
if (res) {
shouldChange = false
}
return res
}
})
function confirmLeave(current, next) {
if (current.type === 'LIST' && next.type === 'HOME') {
return 'are u sure u wanna leave?'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment