Last active
August 18, 2017 05:07
-
-
Save faceyspacey/e7225d6dae7f8226a3ac6e9d1f718d60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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