Created
June 21, 2015 05:04
-
-
Save botanicus/475876e223c301740ff3 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
import {Link} from 'react-router'; | |
import React from 'react/addons'; | |
// <Link to="post" params={{slug: post.slug}} /> | |
export default class LinkToUnlessCurrent extends React.Component { | |
render() { | |
this.element = ( | |
<Link to={this.props.to} params={this.props.params}> | |
{this.props.children} | |
</Link> | |
); | |
var html = React.renderToString(this.element); | |
var link = html.match(/.*href="([^"]+).*"/)[1]; | |
if (window.location.pathname === link) { | |
return <span>{this.props.children}</span>; | |
} else { | |
return this.element; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment