File tree Expand file tree Collapse file tree 2 files changed +30
-17
lines changed Expand file tree Collapse file tree 2 files changed +30
-17
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import { Router , Link } from 'react-router'
2+ import { Link } from 'react-router'
33
44class LinksApp extends React . Component
55{
66 constructor ( props , context ) {
77 super ( props , context ) ;
88 this . generate = this . generate . bind ( this ) ;
9- this . handleLogout = this . handleLogout . bind ( this ) ;
109 this . handleClick = this . handleClick . bind ( this ) ;
1110 this . state = {
12- links : [
13- [ '/' , 'Home' ] ,
14- [ '/client' , 'Client' ] ,
15- [ '/area' , 'Area' ]
16- ]
11+ links : this . props . links || [ ]
1712 } ;
1813 }
1914
20- handleLogout ( ) {
21- delete localStorage . token ;
22- this . context . router . push ( "/" ) ;
23- }
24-
2515 handleClick ( e ) {
2616 if ( this . context . onClick ) {
2717 this . context . onClick ( ) ;
@@ -46,16 +36,16 @@ class LinksApp extends React.Component
4636 return (
4737 < span className = "nav-right nav-menu is-active" >
4838 { this . generate ( ) }
49- < span className = "nav-item" >
50- < a className = "button" onClick = { this . handleLogout } > Logout</ a >
51- </ span >
5239 </ span >
5340 ) ;
5441 }
5542}
5643
44+ LinksApp . propTypes = {
45+ links : React . PropTypes . array . isRequired
46+ } ;
47+
5748LinksApp . contextTypes = {
58- router : React . PropTypes . object . isRequired ,
5949 onClick : React . PropTypes . func
6050} ;
6151
Original file line number Diff line number Diff line change 11import React from 'react' ;
2+ import { Router } from 'react-router'
23
34import Nav from 'components/Nav/Nav'
45import LinksApp from 'components/LinksApp/LinksApp'
@@ -7,13 +8,31 @@ import LinksApp from 'components/LinksApp/LinksApp'
78class Menu extends React . Component {
89 constructor ( props , context ) {
910 super ( props , context ) ;
11+ this . handleLogout = this . handleLogout . bind ( this ) ;
1012 this . handleView = this . handleView . bind ( this ) ;
13+ this . state = {
14+ links : [
15+ [ '/' , 'Home' ] ,
16+ [ '/client' , 'Client' ] ,
17+ [ '/area' , 'Area' ]
18+ ]
19+ } ;
20+ }
21+
22+ handleLogout ( ) {
23+ delete localStorage . token ;
24+ this . context . router . push ( "/" ) ;
1125 }
1226
1327 handleView ( ) {
1428 return (
1529 < Nav >
16- < LinksApp />
30+ < LinksApp
31+ links = { this . state . links }
32+ />
33+ < span className = "nav-item" >
34+ < a className = "button" onClick = { this . handleLogout } > Logout</ a >
35+ </ span >
1736 </ Nav >
1837 ) ;
1938 }
@@ -30,5 +49,9 @@ class Menu extends React.Component{
3049 }
3150}
3251
52+ Menu . contextTypes = {
53+ router : React . PropTypes . object . isRequired
54+ } ;
55+
3356export default Menu ;
3457
You can’t perform that action at this time.
0 commit comments