@@ -173,9 +173,9 @@ function createRouter(options) {
173
173
} ,
174
174
175
175
clearAllRoutes : function ( ) {
176
- this . cancelPendingTransition ( ) ;
177
- this . namedRoutes = { } ;
178
- this . routes = [ ] ;
176
+ Router . cancelPendingTransition ( ) ;
177
+ Router . namedRoutes = { } ;
178
+ Router . routes = [ ] ;
179
179
} ,
180
180
181
181
/**
@@ -185,18 +185,18 @@ function createRouter(options) {
185
185
if ( isReactChildren ( routes ) )
186
186
routes = createRoutesFromReactChildren ( routes ) ;
187
187
188
- addRoutesToNamedRoutes ( routes , this . namedRoutes ) ;
188
+ addRoutesToNamedRoutes ( routes , Router . namedRoutes ) ;
189
189
190
- this . routes . push . apply ( this . routes , routes ) ;
190
+ Router . routes . push . apply ( Router . routes , routes ) ;
191
191
} ,
192
192
193
193
/**
194
194
* Replaces routes of this router from the given children object (see ReactChildren).
195
195
*/
196
196
replaceRoutes : function ( routes ) {
197
- this . clearAllRoutes ( ) ;
198
- this . addRoutes ( routes ) ;
199
- this . refresh ( ) ;
197
+ Router . clearAllRoutes ( ) ;
198
+ Router . addRoutes ( routes ) ;
199
+ Router . refresh ( ) ;
200
200
} ,
201
201
202
202
/**
@@ -205,7 +205,7 @@ function createRouter(options) {
205
205
* match can be made.
206
206
*/
207
207
match : function ( path ) {
208
- return Match . findMatch ( this . routes , path ) ;
208
+ return Match . findMatch ( Router . routes , path ) ;
209
209
} ,
210
210
211
211
/**
@@ -217,7 +217,7 @@ function createRouter(options) {
217
217
if ( PathUtils . isAbsolute ( to ) ) {
218
218
path = to ;
219
219
} else {
220
- var route = ( to instanceof Route ) ? to : this . namedRoutes [ to ] ;
220
+ var route = ( to instanceof Route ) ? to : Router . namedRoutes [ to ] ;
221
221
222
222
invariant (
223
223
route instanceof Route ,
@@ -236,7 +236,7 @@ function createRouter(options) {
236
236
* to the route with the given name, URL parameters, and query.
237
237
*/
238
238
makeHref : function ( to , params , query ) {
239
- var path = this . makePath ( to , params , query ) ;
239
+ var path = Router . makePath ( to , params , query ) ;
240
240
return ( location === HashLocation ) ? '#' + path : path ;
241
241
} ,
242
242
@@ -245,7 +245,7 @@ function createRouter(options) {
245
245
* a new URL onto the history stack.
246
246
*/
247
247
transitionTo : function ( to , params , query ) {
248
- var path = this . makePath ( to , params , query ) ;
248
+ var path = Router . makePath ( to , params , query ) ;
249
249
250
250
if ( pendingTransition ) {
251
251
// Replace so pending location does not stay in history.
@@ -260,7 +260,7 @@ function createRouter(options) {
260
260
* the current URL in the history stack.
261
261
*/
262
262
replaceWith : function ( to , params , query ) {
263
- location . replace ( this . makePath ( to , params , query ) ) ;
263
+ location . replace ( Router . makePath ( to , params , query ) ) ;
264
264
} ,
265
265
266
266
/**
@@ -292,7 +292,7 @@ function createRouter(options) {
292
292
if ( abortReason instanceof Cancellation ) {
293
293
return ;
294
294
} else if ( abortReason instanceof Redirect ) {
295
- location . replace ( this . makePath ( abortReason . to , abortReason . params , abortReason . query ) ) ;
295
+ location . replace ( Router . makePath ( abortReason . to , abortReason . params , abortReason . query ) ) ;
296
296
} else {
297
297
location . pop ( ) ;
298
298
}
@@ -304,7 +304,7 @@ function createRouter(options) {
304
304
} ,
305
305
306
306
handleLocationChange : function ( change ) {
307
- this . dispatch ( change . path , change . type ) ;
307
+ Router . dispatch ( change . path , change . type ) ;
308
308
} ,
309
309
310
310
/**
@@ -324,7 +324,7 @@ function createRouter(options) {
324
324
* hooks wait, the transition is fully synchronous.
325
325
*/
326
326
dispatch : function ( path , action ) {
327
- this . cancelPendingTransition ( ) ;
327
+ Router . cancelPendingTransition ( ) ;
328
328
329
329
var prevPath = state . path ;
330
330
var isRefreshing = action == null ;
@@ -335,9 +335,9 @@ function createRouter(options) {
335
335
// Record the scroll position as early as possible to
336
336
// get it before browsers try update it automatically.
337
337
if ( prevPath && action === LocationActions . PUSH )
338
- this . recordScrollPosition ( prevPath ) ;
338
+ Router . recordScrollPosition ( prevPath ) ;
339
339
340
- var match = this . match ( path ) ;
340
+ var match = Router . match ( path ) ;
341
341
342
342
warning (
343
343
match != null ,
@@ -370,7 +370,7 @@ function createRouter(options) {
370
370
toRoutes = nextRoutes ;
371
371
}
372
372
373
- var transition = new Transition ( path , this . replaceWith . bind ( this , path ) ) ;
373
+ var transition = new Transition ( path , Router . replaceWith . bind ( Router , path ) ) ;
374
374
pendingTransition = transition ;
375
375
376
376
var fromComponents = mountedComponents . slice ( prevRoutes . length - fromRoutes . length ) ;
@@ -401,7 +401,7 @@ function createRouter(options) {
401
401
*/
402
402
run : function ( callback ) {
403
403
invariant (
404
- ! this . isRunning ,
404
+ ! Router . isRunning ,
405
405
'Router is already running'
406
406
) ;
407
407
@@ -417,32 +417,32 @@ function createRouter(options) {
417
417
if ( transition . abortReason ) {
418
418
Router . handleAbort ( transition . abortReason ) ;
419
419
} else {
420
- callback . call ( this , this , nextState = newState ) ;
420
+ callback . call ( Router , Router , nextState = newState ) ;
421
421
}
422
422
} ;
423
423
424
424
if ( ! ( location instanceof StaticLocation ) ) {
425
425
if ( location . addChangeListener )
426
- location . addChangeListener ( Router . handleLocationChange . bind ( Router ) ) ;
426
+ location . addChangeListener ( Router . handleLocationChange ) ;
427
427
428
- this . isRunning = true ;
428
+ Router . isRunning = true ;
429
429
}
430
430
431
431
// Bootstrap using the current path.
432
- this . refresh ( ) ;
432
+ Router . refresh ( ) ;
433
433
} ,
434
434
435
435
refresh : function ( ) {
436
436
Router . dispatch ( location . getCurrentPath ( ) , null ) ;
437
437
} ,
438
438
439
439
stop : function ( ) {
440
- this . cancelPendingTransition ( ) ;
440
+ Router . cancelPendingTransition ( ) ;
441
441
442
442
if ( location . removeChangeListener )
443
- location . removeChangeListener ( Router . handleLocationChange . bind ( Router ) ) ;
443
+ location . removeChangeListener ( Router . handleLocationChange ) ;
444
444
445
- this . isRunning = false ;
445
+ Router . isRunning = false ;
446
446
} ,
447
447
448
448
getLocation : function ( ) {
0 commit comments