Created
December 7, 2017 21:08
-
-
Save jacobwallenberg/a6b2bbd2453f39777dccf6faa1eda32c 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
import React from 'react' | |
import { | |
BrowserRouter as Router, | |
Route, | |
Link | |
} from 'react-router-dom' | |
const CustomLinkExample = () => ( | |
<Router> | |
<div> | |
<OldSchoolMenuLink activeOnlyWhenExact={true} to="/" label="Home"/> | |
<OldSchoolMenuLink to="/about" label="About"/> | |
<hr/> | |
<Route exact path="/" component={Home}/> | |
<Route path="/about" component={About}/> | |
</div> | |
</Router> | |
) | |
const OldSchoolMenuLink = ({ label, to, activeOnlyWhenExact }) => ( | |
<Route path={to} exact={activeOnlyWhenExact} children={({ match }) => ( | |
<div className={match ? 'active' : ''}> | |
{match ? '> ' : ''}<Link to={to}>{label}</Link> | |
</div> | |
)}/> | |
) | |
const Home = () => ( | |
<div> | |
<h2>Home</h2> | |
</div> | |
) | |
const About = () => ( | |
<div> | |
<h2>About</h2> | |
</div> | |
) | |
export default CustomLinkExample |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment