Skip to content

Instantly share code, notes, and snippets.

@HarisSpahija
Last active Oct 6, 2019
Embed
What would you like to do?
// Import Router at the top of the page
import {
BrowserRouter as Router,
Link,
Route
} from "react-router-dom";
render() {
const { pages } = this.state;
return (
<Router>
<Fragment>
{/* Links */}
<div class="topnav">
{pages.map((page, index) => {
return <Link to={page.slug}>{page.slug}</Link>;
})}
</div>
{/* Routing */}
{pages.map((page, index) => {
return (
<Route
exact
key={index}
path={`/${page.slug}`}
render={props => (
<ExamplePage {...props} page={page} />
)}
/>
);
})}
</Fragment>
</Router>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment