@@ -157,6 +157,7 @@ function createRouter(options) {
157
157
var state = { } ;
158
158
var nextState = { } ;
159
159
var pendingTransition = null ;
160
+ var dispatchHandler = null ;
160
161
var changeListener = null ;
161
162
162
163
function cancelPendingTransition ( ) {
@@ -209,6 +210,19 @@ function createRouter(options) {
209
210
routes . push . apply ( routes , createRoutesFromChildren ( children , this , namedRoutes ) ) ;
210
211
} ,
211
212
213
+ /**
214
+ * Replaces routes of this router from the given children object (see ReactChildren).
215
+ */
216
+ replaceRoutes : function ( children ) {
217
+ cancelPendingTransition ( ) ;
218
+
219
+ routes = [ ] ;
220
+ namedRoutes = { } ;
221
+
222
+ this . addRoutes ( children ) ;
223
+ this . refresh ( ) ;
224
+ } ,
225
+
212
226
/**
213
227
* Returns an absolute URL path created from the given route
214
228
* name, URL parameters, and query.
@@ -325,11 +339,13 @@ function createRouter(options) {
325
339
* transition. To resolve asynchronously, they may use the callback argument. If no
326
340
* hooks wait, the transition is fully synchronous.
327
341
*/
328
- dispatch : function ( path , action , callback ) {
342
+ dispatch : function ( path , action ) {
329
343
cancelPendingTransition ( ) ;
330
344
331
345
var prevPath = state . path ;
332
- if ( prevPath === path )
346
+ var isRefreshing = action == null ;
347
+
348
+ if ( prevPath === path && ! isRefreshing )
333
349
return ; // Nothing to do!
334
350
335
351
// Record the scroll position as early as possible to
@@ -378,11 +394,11 @@ function createRouter(options) {
378
394
379
395
transition . from ( fromRoutes , fromComponents , function ( error ) {
380
396
if ( error || transition . isAborted )
381
- return callback . call ( router , error , transition ) ;
397
+ return dispatchHandler . call ( router , error , transition ) ;
382
398
383
399
transition . to ( toRoutes , nextParams , nextQuery , function ( error ) {
384
400
if ( error || transition . isAborted )
385
- return callback . call ( router , error , transition ) ;
401
+ return dispatchHandler . call ( router , error , transition ) ;
386
402
387
403
nextState . path = path ;
388
404
nextState . action = action ;
@@ -391,7 +407,7 @@ function createRouter(options) {
391
407
nextState . params = nextParams ;
392
408
nextState . query = nextQuery ;
393
409
394
- callback . call ( router , null , transition ) ;
410
+ dispatchHandler . call ( router , null , transition ) ;
395
411
} ) ;
396
412
} ) ;
397
413
} ,
@@ -409,7 +425,7 @@ function createRouter(options) {
409
425
'Router is already running'
410
426
) ;
411
427
412
- var dispatchHandler = function ( error , transition ) {
428
+ dispatchHandler = function ( error , transition ) {
413
429
if ( error )
414
430
onError . call ( router , error ) ;
415
431
@@ -426,18 +442,18 @@ function createRouter(options) {
426
442
} ;
427
443
428
444
if ( typeof location === 'string' ) {
429
- router . dispatch ( location , null , dispatchHandler ) ;
445
+ router . dispatch ( location , null ) ;
430
446
} else {
431
447
// Listen for changes to the location.
432
448
changeListener = function ( change ) {
433
- router . dispatch ( change . path , change . type , dispatchHandler ) ;
449
+ router . dispatch ( change . path , change . type ) ;
434
450
} ;
435
451
436
452
if ( location . addChangeListener )
437
453
location . addChangeListener ( changeListener ) ;
438
454
439
455
// Bootstrap using the current path.
440
- router . dispatch ( location . getCurrentPath ( ) , null , dispatchHandler ) ;
456
+ this . refresh ( ) ;
441
457
442
458
this . isRunning = true ;
443
459
}
@@ -452,6 +468,10 @@ function createRouter(options) {
452
468
}
453
469
454
470
this . isRunning = false ;
471
+ } ,
472
+
473
+ refresh : function ( ) {
474
+ router . dispatch ( location . getCurrentPath ( ) , null ) ;
455
475
}
456
476
457
477
} ,
0 commit comments