Created
March 24, 2015 06:08
-
-
Save jmfurlott/e723df3110c513be5de9 to your computer and use it in GitHub Desktop.
react-router context issue
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 from 'react'; | |
import { RouteHandler } from 'react-router'; | |
let AppHandler = React.createClass( | |
render() { | |
return ( | |
<div> | |
... | |
<div> | |
<RouteHandler /> | |
</div> | |
</div> | |
); | |
}, | |
}); | |
export default AppHandler; |
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
'use strict'; | |
import React from 'react'; | |
let Login = React.createClass({ | |
contextTypes: { | |
flux: React.PropTypes.object.isRequired, | |
router: React.PropTypes.func.isRequired, | |
}, | |
getInitialState() { | |
return({ | |
username: "[email protected]", | |
password: '' | |
}); | |
}, | |
async onLogin(event) { | |
event.preventDefault(); | |
this.sessionActions = this.context.flux.getActions('session'); | |
console.log(await this.sessionActions.getToken()); | |
}, | |
onUsernameChange(event) { | |
this.setState({ | |
username: event.target.value | |
}); | |
}, | |
onPasswordChange(event) { | |
this.setState({ | |
password: event.target.value | |
}); | |
}, | |
render() { | |
console.log(this.context.router); | |
return( | |
<div className="Login"> | |
<h3>Login</h3> | |
<p>Forgot your password?</p> | |
<form onSubmit={this.onLogin}> | |
... | |
</form> | |
</div> | |
); | |
} | |
}); | |
export default Login; |
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 from 'react'; | |
import { Route, DefaultRoute } from 'react-router'; | |
import AppHandler from './components/AppHandler'; | |
import Login from './components/Session/Login'; | |
import Logout from './components/Session/Logout'; | |
import Dashboard from './components/Dashboard'; | |
let Routes = ( | |
<Route name="app" path="/" handler={AppHandler}> | |
<Route name="login" path="/login" handler={Login} /> | |
<Route name="logout" path="/logout" handler={Logout} /> | |
<Route name="dashboard" path="/dashboard" handler={Dashboard} /> | |
</Route> | |
); | |
export default Routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that's weird ... this works for me with [email protected]