Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created February 23, 2017 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iammerrick/6edd680cca72f7f3e7375ffe52e38cbd to your computer and use it in GitHub Desktop.
Save iammerrick/6edd680cca72f7f3e7375ffe52e38cbd to your computer and use it in GitHub Desktop.
React Router 4 is fundamentally different because it allows for nested routes that rely on parent context. This facilitates recursive routes and other B-E-A-UTIFUL things.
import React from 'react'
import {
BrowserRouter as Router,
Route,
Link
} from 'react-router-dom'
const BasicExample = () => (
<Router>
<div>
<ul>
<li><Link to="/topics">Topics</Link></li>
</ul>
<Route path="/topics" component={Topics}/>
</div>
</Router>
)
const Topics = ({ match }) => (
<div>
<h2>Topics</h2>
<ul>
<li><Link to={`${match.url}/rendering`}>Rendering with React</Link></li>
<li><Link to={`${match.url}/components`}>Components</Link></li>
<li><Link to={`${match.url}/props-v-state`}>Props v. State</Link></li>
</ul>
<Route path={`${match.url}/:topicId`} component={Topic}/>
<Route exact path={match.url} render={() => (
<h3>Please select a topic.</h3>
)}/>
</div>
)
const Topic = ({ match }) => (
<div>
<h3>{match.params.topicId}</h3>
</div>
)
export default BasicExample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment