-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathApp.js
54 lines (49 loc) · 1.43 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { Component } from 'react';
import { Link } from 'react-router';
import './App.css';
import octocat from './octocat.svg';
const LINKS = [
{path: "/", name: "SongSim"},
{path: "/about", name: "About"},
{path: "/gallery", name: "Gallery"}
];
class App extends Component {
renderNavLink = (link) => {
// I'm sure there's a better way to do this...
let active = link.path === "/" ?
!LINKS.some((l) =>
( l.path !== "/" && this.props.location.pathname.startsWith(l.path))
)
:
this.props.location.pathname.startsWith(link.path)
;
return (<li className={"navLink" + link.name + (active ? " active" : "")}
key={link.name}
>
<Link to={link.path}>{link.name}</Link></li>);
}
render() {
var links = LINKS.map(this.renderNavLink);
return (
<div className="App">
<nav className="navbar navbar-default">
<div className="container-fluid">
<ul className="nav navbar-nav">
{links}
<li className="octo">
<a title="Fork me on GitHub"
href="https://github.com/colinmorris/SongSim"
target="_blank"
>
<img alt="octocat" src={octocat} />
</a>
</li>
</ul>
</div>
</nav>
{this.props.children}
</div>
);
}
}
export default App;