Skip to content

Instantly share code, notes, and snippets.

@eplawless
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save eplawless/b17ba00bd3e15cc121a5 to your computer and use it in GitHub Desktop.

Select an option

Save eplawless/b17ba00bd3e15cc121a5 to your computer and use it in GitHub Desktop.

Revisions

  1. eplawless revised this gist Jun 16, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions getNavigation.js
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,8 @@ function getNavigation({ React }) {
    return router[method].apply(router, arguments);
    };
    });

    return Navigation;
    }

    export default getNavigation;
  2. eplawless created this gist Jun 16, 2015.
    3 changes: 3 additions & 0 deletions Navigation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    import getNavigation from './getNavigation';
    import React from 'react';
    export default getNavigation({ React });
    51 changes: 51 additions & 0 deletions getNavigation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    function getNavigation({ 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 getNavigation;