Created
September 13, 2016 18:07
-
-
Save olov/76f3e4c4ced859834cf66471adb43dd4 to your computer and use it in GitHub Desktop.
what prevents this kind of react-router API?
This file contains 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
// Run this example locally by copy/pasting it into | |
// `src/App.js` of an app created with `create-react-app` | |
// https://github.com/facebookincubator/create-react-app | |
import React from 'react' | |
import Match from 'react-router/Match' | |
import Miss from 'react-router/Miss' | |
import Link from 'react-router/Link' | |
import Redirect from 'react-router/Redirect' | |
import Router from 'react-router/BrowserRouter' | |
class BasicExample extends React.Component { | |
render() { | |
return ( | |
<Router> | |
<div> | |
<ul> | |
<li><Link to="/">Home</Link></li> | |
<li><Link to="/about">About</Link></li> | |
<li><Link to="/topics">Topics</Link></li> | |
</ul> | |
<hr/> | |
<Match exactly pattern="/"><Home/></Match> | |
<Match pattern="/about"><About/></Match> | |
<Match pattern="/topics"><Topics/></Match> | |
</div> | |
</Router> | |
) | |
} | |
} | |
const Home = () => ( | |
<div> | |
<h2>Home</h2> | |
</div> | |
) | |
const About = () => ( | |
<div> | |
<h2>About</h2> | |
</div> | |
) | |
const Topics = ({ pathname }) => ( | |
<div> | |
<h2>Topics</h2> | |
<ul> | |
<li><Link to={`${pathname}/rendering`}>Rendering with React</Link></li> | |
<li><Link to={`${pathname}/components`}>Components</Link></li> | |
<li><Link to={`${pathname}/props-v-state`}>Props v. State</Link></li> | |
</ul> | |
<Match pattern={`${pathname}/:topicId`}><Topic/></Match> | |
<Match pattern={pathname} exactly> | |
<h3>Please select a topic</h3> | |
</Match> | |
</div> | |
) | |
const Topic = ({ params }) => ( | |
<div> | |
<h3>{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