Skip to content

Instantly share code, notes, and snippets.

@alexnm
Created March 25, 2018 20:28
Show Gist options
  • Save alexnm/b1f0b9916fd8ccc2f4946de287b0618a to your computer and use it in GitHub Desktop.
Save alexnm/b1f0b9916fd8ccc2f4946de287b0618a to your computer and use it in GitHub Desktop.
Basic layout with Routes
import { Link, Switch, Route } from "react-router-dom";
import Home from "./Home";
import About from "./About";
import Contact from "./Contact";
export default class Layout extends React.Component {
/* ... */
render() {
return (
<div>
<h1>{ this.state.title }</h1>
<div>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/contact">Contact</Link>
</div>
<Switch>
<Route path="/" exact component={ Home } />
<Route path="/about" exact component={ About } />
<Route path="/contact" exact component={ Contact } />
</Switch>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment