Skip to content

Instantly share code, notes, and snippets.

@gaearon
Created November 3, 2014 15:51
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 gaearon/de79faa3eda52493435f to your computer and use it in GitHub Desktop.
Save gaearon/de79faa3eda52493435f to your computer and use it in GitHub Desktop.
Navigation that can be used from Actions
/*
Usage:
var routes = React.renderComponent(
<Routes location='history'>...</Routes>,
document.body
);
Navigation.injectRoutesInstance(routes);
// and later in action creators just use Navigation
*/
'use strict';
var invariant = require('react/lib/invariant');
var _routes;
/**
* Provides react-router/Navigation API that can be used
* from outside the components (e.g. from action creators).
*/
module.exports = {
injectRoutesInstance(routes) {
invariant(!_routes, 'Expected injection to happen once.');
_routes = routes;
},
makePath(to, params, query) {
return _routes.makePath(to, params, query);
},
makeHref(to, params, query) {
return _routes.makeHref(to, params, query);
},
transitionTo(to, params, query) {
_routes.transitionTo(to, params, query);
},
replaceWith(to, params, query) {
_routes.replaceWith(to, params, query);
},
goBack() {
_routes.goBack();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment