Last active
September 21, 2015 15:36
-
-
Save clalimarmo/63895edd6cad3a5a928e to your computer and use it in GitHub Desktop.
Deep Linking with React + Flux, URL Store, with support for browser "back"
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
(function() { | |
Dispather.register(function(action) { | |
if (action.type !== 'navigate') { | |
return; | |
} | |
// sometimes we don't want to create history entries (see below) | |
if (action.pushState) { | |
window.history.pushState( | |
{path: action.path}, | |
'', | |
action.path | |
); | |
} | |
}); | |
window.onpopstate = function(event) { | |
// only handle browser back if our app created the history entry | |
if (event.state.path) { | |
Dispatcher.dispatch({ | |
type: 'navigate', | |
path: event.state.path, | |
// navigating back shouldn't add anything to the browsing history | |
pushState: false, | |
}); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment