@@ -74,12 +74,30 @@ var Route = React.createClass({
74
74
75
75
statics : {
76
76
77
- handleAsyncError : function ( error ) {
77
+ getUnreservedProps : function ( props ) {
78
+ return withoutProperties ( props , RESERVED_PROPS ) ;
79
+ } ,
80
+
81
+ /**
82
+ * Handles errors that were thrown asynchronously. By default, the
83
+ * error is re-thrown so we don't swallow them silently.
84
+ */
85
+ handleAsyncError : function ( error , route ) {
78
86
throw error ; // This error probably originated in a transition hook.
79
87
} ,
80
88
81
- getUnreservedProps : function ( props ) {
82
- return withoutProperties ( props , RESERVED_PROPS ) ;
89
+ /**
90
+ * Handles cancelled transitions. By default, redirects replace the
91
+ * current URL and aborts roll it back.
92
+ */
93
+ handleCancelledTransition : function ( transition , route ) {
94
+ var reason = transition . cancelReason ;
95
+
96
+ if ( reason instanceof Redirect ) {
97
+ replaceWith ( reason . to , reason . params , reason . query ) ;
98
+ } else if ( reason instanceof Abort ) {
99
+ goBack ( ) ;
100
+ }
83
101
}
84
102
85
103
} ,
@@ -169,30 +187,28 @@ var Route = React.createClass({
169
187
*/
170
188
dispatch : function ( path , returnRejectedPromise ) {
171
189
var transition = new Transition ( path ) ;
190
+ var route = this ;
172
191
173
- return syncWithTransition ( this , transition ) . then ( function ( newState ) {
192
+ var promise = syncWithTransition ( route , transition ) . then ( function ( newState ) {
174
193
if ( transition . isCancelled ) {
175
- var reason = transition . cancelReason ;
176
-
177
- if ( reason instanceof Redirect ) {
178
- replaceWith ( reason . to , reason . params , reason . query ) ;
179
- } else if ( reason instanceof Abort ) {
180
- goBack ( ) ;
181
- }
194
+ Route . handleCancelledTransition ( transition , route ) ;
182
195
} else if ( newState ) {
183
196
ActiveStore . update ( newState ) ;
184
197
}
185
198
186
199
return transition ;
187
- } ) . then ( undefined , function ( error ) {
188
- if ( returnRejectedPromise )
189
- throw error ;
200
+ } ) ;
190
201
191
- // Use setTimeout to break the promise chain.
192
- setTimeout ( function ( ) {
193
- Route . handleAsyncError ( error ) ;
202
+ if ( ! returnRejectedPromise ) {
203
+ promise = promise . then ( undefined , function ( error ) {
204
+ // Use setTimeout to break the promise chain.
205
+ setTimeout ( function ( ) {
206
+ Route . handleAsyncError ( error , route ) ;
207
+ } ) ;
194
208
} ) ;
195
- } ) ;
209
+ }
210
+
211
+ return promise ;
196
212
} ,
197
213
198
214
render : function ( ) {
0 commit comments