1
1
var React = require ( 'react' ) ;
2
2
var Router = require ( 'react-router' ) ;
3
- var { Route, RouteHandler, Link } = Router ;
3
+ var { Route, RouteHandler, Link, State } = Router ;
4
4
5
5
var App = React . createClass ( {
6
6
getInitialState : function ( ) {
@@ -40,9 +40,10 @@ var App = React.createClass({
40
40
var Authentication = {
41
41
statics : {
42
42
willTransitionTo : function ( transition ) {
43
+ var nextPath = transition . path ;
43
44
if ( ! auth . loggedIn ( ) ) {
44
- Login . attemptedTransition = transition ;
45
- transition . redirect ( '/login' ) ;
45
+ transition . redirect ( '/login' , { } ,
46
+ { 'nextPath' : nextPath } ) ;
46
47
}
47
48
}
48
49
}
@@ -64,11 +65,7 @@ var Dashboard = React.createClass({
64
65
} ) ;
65
66
66
67
var Login = React . createClass ( {
67
- mixins : [ Router . Navigation ] ,
68
-
69
- statics : {
70
- attemptedTransition : null
71
- } ,
68
+ mixins : [ Router . Navigation , State ] ,
72
69
73
70
getInitialState : function ( ) {
74
71
return {
@@ -78,16 +75,15 @@ var Login = React.createClass({
78
75
79
76
handleSubmit : function ( event ) {
80
77
event . preventDefault ( ) ;
78
+ var nextPath = this . getQuery ( ) . nextPath ;
81
79
var email = this . refs . email . getDOMNode ( ) . value ;
82
80
var pass = this . refs . pass . getDOMNode ( ) . value ;
83
81
auth . login ( email , pass , function ( loggedIn ) {
84
82
if ( ! loggedIn )
85
83
return this . setState ( { error : true } ) ;
86
84
87
- if ( Login . attemptedTransition ) {
88
- var transition = Login . attemptedTransition ;
89
- Login . attemptedTransition = null ;
90
- transition . retry ( ) ;
85
+ if ( nextPath ) {
86
+ this . transitionTo ( nextPath ) ;
91
87
} else {
92
88
this . replaceWith ( '/about' ) ;
93
89
}
0 commit comments