@@ -44,15 +44,11 @@ function useRoutes(createHistory) {
44
44
} else {
45
45
matchRoutes ( routes , location , function ( error , nextState ) {
46
46
if ( error ) {
47
- callback ( error , null , null )
47
+ callback ( error )
48
48
} else if ( nextState ) {
49
- finishMatch ( { ...nextState , location } , function ( err , nextLocation , nextState ) {
50
- if ( nextState )
51
- state = nextState
52
- callback ( err , nextLocation , nextState )
53
- } )
49
+ finishMatch ( { ...nextState , location } , callback )
54
50
} else {
55
- callback ( null , null , null )
51
+ callback ( )
56
52
}
57
53
} )
58
54
}
@@ -73,7 +69,7 @@ function useRoutes(createHistory) {
73
69
if ( error ) {
74
70
callback ( error )
75
71
} else if ( redirectInfo ) {
76
- callback ( null , createLocationFromRedirectInfo ( redirectInfo ) , null )
72
+ callback ( null , createLocationFromRedirectInfo ( redirectInfo ) )
77
73
} else {
78
74
// TODO: Fetch components after state is updated.
79
75
getComponents ( nextState , function ( error , components ) {
@@ -215,12 +211,9 @@ function useRoutes(createHistory) {
215
211
}
216
212
217
213
/**
218
- * This is the API for stateful environments. As the location changes,
219
- * we update state and call the listener. Benefits of this API are:
220
- *
221
- * - We automatically manage state on the client
222
- * - We automatically handle redirects on the client
223
- * - We warn when the location doesn't match any routes
214
+ * This is the API for stateful environments. As the location
215
+ * changes, we update state and call the listener. We can also
216
+ * gracefully handle errors and redirects.
224
217
*/
225
218
function listen ( listener ) {
226
219
return history . listen ( function ( location ) {
@@ -230,10 +223,10 @@ function useRoutes(createHistory) {
230
223
match ( location , function ( error , nextLocation , nextState ) {
231
224
if ( error ) {
232
225
listener ( error )
233
- } else if ( nextState ) {
234
- listener ( null , state ) // match mutates state to nextState
235
226
} else if ( nextLocation ) {
236
227
history . transitionTo ( nextLocation )
228
+ } else if ( nextState ) {
229
+ listener ( null , ( state = nextState ) )
237
230
} else {
238
231
warning (
239
232
false ,
0 commit comments