mowgli
Version:
Thin layer over React JS for interacting with a single tree of state
25 lines (19 loc) • 502 B
JavaScript
;
import React from 'react';
const button = React.createFactory('button');
export default React.createClass({
displayName: 'RouteButton',
contextTypes: {
router: React.PropTypes.func
},
_handleClick: function() {
const pathName = this.context.router.getCurrentPathname();
const toRoute = pathName === '/' ? 'another' : '/';
this.context.router.transitionTo(toRoute);
},
render: function() {
return button({
onClick: this._handleClick
}, 'ChangeRoute');
}
});