@@ -44,15 +44,11 @@ function useRoutes(createHistory) {
4444 } else {
4545 matchRoutes ( routes , location , function ( error , nextState ) {
4646 if ( error ) {
47- callback ( error , null , null )
47+ callback ( error )
4848 } 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 )
5450 } else {
55- callback ( null , null , null )
51+ callback ( )
5652 }
5753 } )
5854 }
@@ -73,7 +69,7 @@ function useRoutes(createHistory) {
7369 if ( error ) {
7470 callback ( error )
7571 } else if ( redirectInfo ) {
76- callback ( null , createLocationFromRedirectInfo ( redirectInfo ) , null )
72+ callback ( null , createLocationFromRedirectInfo ( redirectInfo ) )
7773 } else {
7874 // TODO: Fetch components after state is updated.
7975 getComponents ( nextState , function ( error , components ) {
@@ -215,12 +211,9 @@ function useRoutes(createHistory) {
215211 }
216212
217213 /**
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.
224217 */
225218 function listen ( listener ) {
226219 return history . listen ( function ( location ) {
@@ -230,10 +223,10 @@ function useRoutes(createHistory) {
230223 match ( location , function ( error , nextLocation , nextState ) {
231224 if ( error ) {
232225 listener ( error )
233- } else if ( nextState ) {
234- listener ( null , state ) // match mutates state to nextState
235226 } else if ( nextLocation ) {
236227 history . transitionTo ( nextLocation )
228+ } else if ( nextState ) {
229+ listener ( null , ( state = nextState ) )
237230 } else {
238231 warning (
239232 false ,
0 commit comments