-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs, examples, and upgrade guide.
Also add an export of withRouter
- Loading branch information
Showing
13 changed files
with
321 additions
and
329 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react' | ||
import { render } from 'react-dom' | ||
import { browserHistory, Router, Route, Link, routerShape } from 'react-router' | ||
import { browserHistory, Router, Route, Link, withRouter } from 'react-router' | ||
import auth from './auth' | ||
|
||
const App = React.createClass({ | ||
|
@@ -55,51 +55,51 @@ const Dashboard = React.createClass({ | |
} | ||
}) | ||
|
||
const Login = React.createClass({ | ||
const Login = withRouter( | ||
React.createClass({ | ||
|
||
contextTypes: { | ||
router: routerShape.isRequired | ||
}, | ||
|
||
getInitialState() { | ||
return { | ||
error: false | ||
} | ||
}, | ||
|
||
handleSubmit(event) { | ||
event.preventDefault() | ||
|
||
const email = this.refs.email.value | ||
const pass = this.refs.pass.value | ||
|
||
auth.login(email, pass, (loggedIn) => { | ||
if (!loggedIn) | ||
return this.setState({ error: true }) | ||
|
||
const { location } = this.props | ||
displayName: 'Login', | ||
|
||
if (location.state && location.state.nextPathname) { | ||
this.context.router.replace(location.state.nextPathname) | ||
} else { | ||
this.context.router.replace('/') | ||
getInitialState() { | ||
return { | ||
error: false | ||
} | ||
}) | ||
}, | ||
|
||
render() { | ||
return ( | ||
<form onSubmit={this.handleSubmit}> | ||
<label><input ref="email" placeholder="email" defaultValue="[email protected]" /></label> | ||
<label><input ref="pass" placeholder="password" /></label> (hint: password1)<br /> | ||
<button type="submit">login</button> | ||
{this.state.error && ( | ||
<p>Bad login information</p> | ||
)} | ||
</form> | ||
) | ||
} | ||
}) | ||
}, | ||
|
||
handleSubmit(event) { | ||
event.preventDefault() | ||
|
||
const email = this.refs.email.value | ||
const pass = this.refs.pass.value | ||
|
||
auth.login(email, pass, (loggedIn) => { | ||
if (!loggedIn) | ||
return this.setState({ error: true }) | ||
|
||
const { location } = this.props | ||
|
||
if (location.state && location.state.nextPathname) { | ||
this.props.router.replace(location.state.nextPathname) | ||
} else { | ||
this.props.router.replace('/') | ||
} | ||
}) | ||
}, | ||
|
||
render() { | ||
return ( | ||
<form onSubmit={this.handleSubmit}> | ||
<label><input ref="email" placeholder="email" defaultValue="[email protected]" /></label> | ||
<label><input ref="pass" placeholder="password" /></label> (hint: password1)<br /> | ||
<button type="submit">login</button> | ||
{this.state.error && ( | ||
<p>Bad login information</p> | ||
)} | ||
</form> | ||
) | ||
} | ||
}) | ||
) | ||
|
||
const About = React.createClass({ | ||
render() { | ||
|
This file contains 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
Oops, something went wrong.