Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@clalimarmo
Last active September 21, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clalimarmo/63895edd6cad3a5a928e to your computer and use it in GitHub Desktop.
Save clalimarmo/63895edd6cad3a5a928e to your computer and use it in GitHub Desktop.
Deep Linking with React + Flux, URL Store, with support for browser "back"
(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