Created
July 14, 2017 09:21
-
-
Save dglowinski/997b086c1d14ce0589396231e585ed01 to your computer and use it in GitHub Desktop.
React - router
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, Link, Route } from 'react-router-dom'; | |
import Footer from './Footer'; | |
import Header from './Header'; | |
import Todos from './Todos'; | |
import Articles from './Articles'; | |
export default class Layout extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
header: "My first React app", | |
footer: "by Dariusz Glowinski" | |
} | |
} | |
render() { | |
const marginStyle = { | |
marginTop: "60px" | |
} | |
return ( | |
<Router> | |
<div > | |
<Header header={this.state.header} /> | |
<Link to="/todos" > Todos </Link> <Link to="/articles"><button>Articles</button></Link> | |
<hr style={marginStyle}/> | |
<Route exact={true} path="/" render={()=>( | |
<h1> Welcome </h1> | |
)}/> | |
<Route path="/todos" component={Todos}/> | |
<Route path="/articles" component={Articles}/> | |
<hr style={marginStyle}/> | |
<Footer footer={this.state.footer} /> | |
</div> | |
</Router> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment