Last active
March 13, 2017 21:09
-
-
Save casprwang/0a90b716fc3a1c2576c7783d6181f10c 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, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import { | |
BrowserRouter as Router, | |
Route, | |
Switch | |
} from 'react-router-dom' | |
// abotuus component | |
const AboutUs = () => ( | |
<div>About us</div> | |
) | |
// home component | |
const Home = () => ( | |
<div> | |
<h3>This is the home</h3> | |
</div> | |
) | |
// Not Found | |
const NotFound = ({location}) => ( | |
<div> | |
<h3>the page { location.pathname } Not found</h3> | |
</div> | |
) | |
// AccountDetails | |
const AccountDetails = ({ match }) => ( | |
<div>Hello, {match.params.username}</div> | |
) | |
class App extends Component { | |
render() { | |
return ( | |
<Router> | |
<div className="App"> | |
<div className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<h2>Welcome to React</h2> | |
</div> | |
<p className="App-intro"> | |
<Switch> | |
<Route path="/aboutus" component={AboutUs} /> | |
<Route path="/" exact component={Home} /> | |
<Route path="/user/:username" component={AccountDetails} /> | |
<Route component={NotFound} /> | |
</Switch> | |
</p> | |
</div> | |
</Router> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment