forked from PacktPublishing/JavaScript-by-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
75 lines (65 loc) · 2.29 KB
/
Copy pathApp.js
File metadata and controls
75 lines (65 loc) · 2.29 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import "bootstrap/dist/css/bootstrap.min.css";
import { Collapse, Navbar, NavbarToggler, Nav, NavItem } from 'reactstrap';
import { NavLink, Route, withRouter } from 'react-router-dom';
import './App.css';
import routes from './routes';
import Home from './Components/Home/Home';
import Post from './Components/Post/Post';
import AuthorList from './Components/Author/AuthorList';
import AuthorPosts from './Components/Author/AuthorPosts';
import NewPost from './Components/NewPost/NewPost';
class App extends Component {
static propTypes = {
history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
}
constructor(props) {
super(props);
this.state = {
isOpen: false,
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
isOpen: !this.state.isOpen
});
}
componentWillMount() {
if(this.props.location.pathname === '/') {
this.props.history.replace(routes.home);
}
}
render() {
return (
<div className="App">
<Navbar color="faded" light toggleable>
<NavbarToggler right onClick={this.toggle} />
<NavLink className="navbar-brand" to={routes.home}>Blog</NavLink>
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink className="nav-link" activeClassName="active" to={routes.home}>Home</NavLink>
</NavItem>
<NavItem>
<NavLink className="nav-link" activeClassName="active" to={routes.authors}>Authors</NavLink>
</NavItem>
<NavItem>
<NavLink className="nav-link" activeClassName="active" to={routes.newPost}>New Post</NavLink>
</NavItem>
</Nav>
</Collapse>
</Navbar>
<Route exact path={routes.home} component={Home} />
<Route exact path={routes.post} component={Post} />
<Route exact path={routes.authors} component={AuthorList} />
<Route exact path={routes.author} component={AuthorPosts} />
<Route exact path={routes.newPost} component={NewPost} />
</div>
);
}
}
export default withRouter(App);