Skip to content

Commit

Permalink
wrap navigation to auto-encode params and queries
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Jun 24, 2015
1 parent 90fe4d4 commit 8fdfb93
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var merge = require('utils-merge');
var createRenderFn = require('./lib/render-fn');
var createDomFn = require('./lib/dom-fn');
var loadingStatus = require('./lib/loading-status');
var Navigation = require('./lib/navigation');

/**
* noop
Expand Down Expand Up @@ -65,7 +66,7 @@ function createComponent(conf, filename) {
// load the standard mixins
var mixins = [
Router.State,
Router.Navigation,
Navigation,
loadingStatus,
events
].concat(conf.mixins || []);
Expand Down
39 changes: 39 additions & 0 deletions lib/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var React = require('react');

module.exports = {
contextTypes: {
makePath: React.PropTypes.func.isRequired,
makeHref: React.PropTypes.func.isRequired,
transitionTo: React.PropTypes.func.isRequired,
replaceWith: React.PropTypes.func.isRequired,
goBack: React.PropTypes.func.isRequired
},

makePath: function(to, params, query) {
params = this.encodeParams(params);
query = this.encodeParams(query);
return this.context.makePath(to, params, query);
},

makeHref: function (to, params, query) {
params = this.encodeParams(params);
query = this.encodeParams(query);
return this.context.makeHref(to, params, query);
},

transitionTo: function (to, params, query) {
params = this.encodeParams(params);
query = this.encodeParams(query);
return this.context.transitionTo(to, params, query);
},

replaceWith: function (to, params, query) {
params = this.encodeParams(params);
query = this.encodeParams(query);
return this.context.replaceWith(to, params, query);
},

goBack: function (to, params, query) {
return this.context.goBack();
}
};

0 comments on commit 8fdfb93

Please sign in to comment.