@@ -82,7 +82,7 @@ function findMatch(pathname, routes, defaultRoute, notFoundRoute) {
82
82
}
83
83
84
84
function createMatch ( route , params ) {
85
- return { path : null , routes : [ route ] , params : params , query : null } ;
85
+ return { routes : [ route ] , params : params } ;
86
86
}
87
87
88
88
function hasMatch ( routes , route , prevParams , nextParams ) {
@@ -238,16 +238,7 @@ function createRouter(options) {
238
238
* the { path, routes, params, query } that match. Returns null if no match can be made.
239
239
*/
240
240
match : function ( path ) {
241
- var pathname = Path . withoutQuery ( path ) ;
242
- var match = findMatch ( pathname , routes , this . defaultRoute , this . notFoundRoute ) ;
243
-
244
- if ( match == null )
245
- return null ;
246
-
247
- match . path = path ;
248
- match . query = Path . extractQuery ( path ) || { } ;
249
-
250
- return match ;
241
+ return findMatch ( Path . withoutQuery ( path ) , routes , this . defaultRoute , this . notFoundRoute ) || null ;
251
242
} ,
252
243
253
244
/**
@@ -266,27 +257,27 @@ function createRouter(options) {
266
257
* transition. To resolve asynchronously, they may use transition.wait(promise). If no
267
258
* hooks wait, the transition is fully synchronous.
268
259
*/
269
- dispatch : function ( action , path , callback ) {
260
+ dispatch : function ( path , action , callback ) {
270
261
if ( state . path === path )
271
262
return ; // Nothing to do!
272
263
273
- var nextState = this . match ( path ) ;
264
+ var match = this . match ( path ) ;
274
265
275
266
warning (
276
- nextState != null ,
267
+ match != null ,
277
268
'No route matches path "%s". Make sure you have <Route path="%s"> somewhere in your routes' ,
278
269
path , path
279
270
) ;
280
271
281
- if ( nextState == null )
282
- nextState = { } ;
272
+ if ( match == null )
273
+ match = { } ;
283
274
284
275
var prevRoutes = state . routes || [ ] ;
285
276
var prevParams = state . params || { } ;
286
277
287
- var nextRoutes = nextState . routes || [ ] ;
288
- var nextParams = nextState . params || { } ;
289
- var nextQuery = nextState . query || { } ;
278
+ var nextRoutes = match . routes || [ ] ;
279
+ var nextParams = match . params || { } ;
280
+ var nextQuery = Path . extractQuery ( path ) || { } ;
290
281
291
282
var fromRoutes , toRoutes ;
292
283
if ( prevRoutes . length ) {
@@ -312,8 +303,11 @@ function createRouter(options) {
312
303
if ( error || transition . isAborted )
313
304
return callback . call ( router , error , transition ) ;
314
305
315
- state = nextState ;
306
+ state . path = path ;
316
307
state . action = action ;
308
+ state . routes = nextRoutes ;
309
+ state . params = nextParams ;
310
+ state . query = nextQuery ;
317
311
318
312
callback . call ( router , null , transition ) ;
319
313
} ) ;
@@ -346,7 +340,7 @@ function createRouter(options) {
346
340
) ;
347
341
348
342
// Dispatch the location.
349
- router . dispatch ( null , location , dispatchHandler ) ;
343
+ router . dispatch ( location , null , dispatchHandler ) ;
350
344
} else {
351
345
invariant (
352
346
canUseDOM ,
@@ -356,14 +350,14 @@ function createRouter(options) {
356
350
357
351
// Listen for changes to the location.
358
352
function changeListener ( change ) {
359
- router . dispatch ( change . type , change . path , dispatchHandler ) ;
353
+ router . dispatch ( change . path , change . type , dispatchHandler ) ;
360
354
}
361
355
362
356
if ( location . addChangeListener )
363
357
location . addChangeListener ( changeListener ) ;
364
358
365
359
// Bootstrap using the current path.
366
- router . dispatch ( null , location . getCurrentPath ( ) , dispatchHandler ) ;
360
+ router . dispatch ( location . getCurrentPath ( ) , null , dispatchHandler ) ;
367
361
}
368
362
}
369
363
0 commit comments