Created
February 5, 2018 21:02
-
-
Save natec425/fa759b38073450398b653cfbfdabf542 to your computer and use it in GitHub Desktop.
React Router Project Groups
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, { Component } from 'react'; | |
import { BrowserRouter as Router, Link, Route } from 'react-router-dom'; | |
const project_groups = { | |
python: [ | |
{ | |
id: 'python-hello', | |
title: 'Hello World', | |
description: 'Hello world in python.' | |
} | |
], | |
javascript: [ | |
{ | |
id: 'js-gladiator', | |
title: 'Gladiator', | |
description: 'Web based gladiator game' | |
} | |
], | |
java: [], | |
haskell: [ | |
{ | |
id: 'hs-dep-types', | |
title: 'Dependent Types in Haskell', | |
description: | |
"Deep dive into Haskell's support for dependent types through building a dependent object calculs interpreter and type checker." | |
} | |
] | |
}; | |
const ProjectGroup = ({ match }) => { | |
let group_name = match.params.projectgroup; | |
let projects = project_groups[group_name]; | |
return ( | |
<div> | |
<h3>{group_name}</h3> | |
<ul> | |
{projects.map(p => ( | |
<li> | |
<h4>{p.title}</h4> | |
<p>{p.description}</p> | |
</li> | |
))} | |
</ul> | |
</div> | |
); | |
}; | |
const ProjectNav = () => { | |
let groups = Object.keys(project_groups); | |
return ( | |
<div> | |
<h3>Groups</h3> | |
{groups.map(g => ( | |
<p> | |
<Link to={g}>{g}</Link> | |
</p> | |
))} | |
</div> | |
); | |
}; | |
class Projects extends Component { | |
render() { | |
return ( | |
<Router> | |
<div> | |
<ProjectNav /> | |
<hr /> | |
<Route path="/:projectgroup" component={ProjectGroup} /> | |
</div> | |
</Router> | |
); | |
} | |
} | |
export default Projects; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment