Created
May 29, 2014 15:23
-
-
Save mmurray/43cc0cc46c02fbaf0321 to your computer and use it in GitHub Desktop.
react-router-link.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Highlighted Link Component extends the react-router Link component | |
* by adding a class to the active link. | |
*/ | |
define(['react', 'react-router'], function(React, Router) { | |
return React.createClass({ | |
mixins: [Router.NavigatableMixin], | |
isActive: function() { | |
return this.getPath() === this.props.href | |
}, | |
render: function() { | |
var className | |
if (this.props.activeClassName && this.isActive()) { | |
className = this.props.activeClassName | |
} | |
var link = Router.Link({className: className}, this.props.children) | |
return this.transferPropsTo(link) | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment