Skip to content

Instantly share code, notes, and snippets.

@dglowinski
Created July 14, 2017 09:21
Show Gist options
  • Save dglowinski/997b086c1d14ce0589396231e585ed01 to your computer and use it in GitHub Desktop.
Save dglowinski/997b086c1d14ce0589396231e585ed01 to your computer and use it in GitHub Desktop.
React - router
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