Skip to content

Instantly share code, notes, and snippets.

@prrraveen
Created September 21, 2018 16:41
Show Gist options
  • Save prrraveen/a3f44404d808843172fdc3125e369520 to your computer and use it in GitHub Desktop.
Save prrraveen/a3f44404d808843172fdc3125e369520 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
const App = () => (
<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 />
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/topics" component={Topics} />
</div>
</Router>
);
const Home = () => (
<div>
<h2>Home</h2>
</div>
);
const About = () => (
<div>
<h2>About</h2>
<section id="hello">
<p style={{height: "1000px"}}> Hello World </p>
</section>
<section id="second">
<p style={{height: "1000px"}}>Second Section</p>
</section>
<section id="third">
<p style={{height: "1000px"}}>Third Section</p>
</section>
</div>
);
const Topics = ({ match }) => (
<div>
<h2>Topics</h2>
<ul>
<li>
<Link to={`${match.url}/rendering`}>Rendering with React</Link>
</li>
<li>
<Link to={`${match.url}/components`}>Components</Link>
</li>
<li>
<Link to={`${match.url}/props-v-state`}>Props v. State</Link>
</li>
</ul>
<Route path={`${match.url}/:topicId`} component={Topic} />
<Route
exact
path={match.url}
render={() => <h3>Please select a topic.</h3>}
/>
</div>
);
const Topic = ({ match }) => (
<div>
<h3>{match.params.topicId}</h3>
</div>
);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment