File tree Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class LinksApp extends React.Component
66 constructor ( props , context ) {
77 super ( props , context ) ;
88 this . generate = this . generate . bind ( this ) ;
9+ this . handleLogout = this . handleLogout . bind ( this ) ;
910 this . state = {
1011 links : [
1112 [ '/' , 'Home' ] ,
@@ -15,6 +16,12 @@ class LinksApp extends React.Component
1516 } ;
1617 }
1718
19+ handleLogout ( ) {
20+ console . log ( 'Marco' , this . context , this . context . router ) ;
21+ delete localStorage . token ;
22+ this . context . router . push ( "/" ) ;
23+ }
24+
1825 generate ( ) {
1926 return this . state . links . map ( ( link , index ) => (
2027 < Link to = { link [ 0 ] }
@@ -31,13 +38,20 @@ class LinksApp extends React.Component
3138 return (
3239 < span className = "nav-right nav-menu is-active" >
3340 { this . generate ( ) }
41+ < span className = "nav-item" >
42+ < a className = "button" onClick = { this . handleLogout } > Logout</ a >
43+ </ span >
3444 </ span >
3545 ) ;
3646 }
3747}
3848
3949LinksApp . propTypes = {
40- hide : React . PropTypes . func . isRequired ,
50+ hide : React . PropTypes . func . isRequired
51+ } ;
52+
53+ LinksApp . contextTypes = {
54+ router : React . PropTypes . object . isRequired
4155} ;
4256
4357export default LinksApp ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import { Router , Link } from 'react-router'
32
43import Nav from 'components/Nav/Nav'
54
65class Menu extends React . Component {
76 constructor ( props , context ) {
87 super ( props , context ) ;
9- this . handleLogout = this . handleLogout . bind ( this ) ;
108 this . handleView = this . handleView . bind ( this ) ;
119 }
1210
13- handleLogout ( ) {
14- delete localStorage . token ;
15- this . context . router . push ( "/" ) ;
16- }
17-
1811 handleView ( ) {
1912 return (
20- < Nav >
21- < span className = "nav-item" >
22- < a className = "button" onClick = { this . handleLogout } > Logout</ a >
23- </ span >
24- </ Nav >
13+ < Nav />
2514 ) ;
2615 }
2716
@@ -37,9 +26,5 @@ class Menu extends React.Component{
3726 }
3827}
3928
40- Menu . contextTypes = {
41- router : React . PropTypes . object . isRequired
42- } ;
43-
4429export default Menu ;
4530
You can’t perform that action at this time.
0 commit comments