react-router
Version:
A complete routing library for React.js
51 lines (43 loc) • 949 B
JavaScript
import React from 'react';
var { object } = React.PropTypes;
/**
* A mixin for components that modify the URL.
*
* Example:
*
* import { Navigation } from 'react-router';
*
* var MyLink = React.createClass({
* mixins: [ Navigation ],
* handleClick(event) {
* event.preventDefault();
* this.transitionTo('aRoute', { the: 'params' }, { the: 'query' });
* },
* render() {
* return (
* <a onClick={this.handleClick}>Click me!</a>
* );
* }
* });
*/
var Navigation = {
contextTypes: {
router: object.isRequired
}
};
var RouterNavigationMethods = [
'makePath',
'makeHref',
'transitionTo',
'replaceWith',
'go',
'goBack',
'goForward'
];
RouterNavigationMethods.forEach(function (method) {
Navigation[method] = function () {
var router = this.context.router;
return router[method].apply(router, arguments);
};
});
export default Navigation;