@@ -8,6 +8,7 @@ var ImitateBrowserBehavior = require('./behaviors/ImitateBrowserBehavior');
8
8
var HashLocation = require ( './locations/HashLocation' ) ;
9
9
var HistoryLocation = require ( './locations/HistoryLocation' ) ;
10
10
var RefreshLocation = require ( './locations/RefreshLocation' ) ;
11
+ var StaticLocation = require ( './locations/StaticLocation' ) ;
11
12
var NavigationContext = require ( './NavigationContext' ) ;
12
13
var StateContext = require ( './StateContext' ) ;
13
14
var Scrolling = require ( './Scrolling' ) ;
@@ -139,6 +140,8 @@ function createRouter(options) {
139
140
'You should not use a static location in a DOM environment because ' +
140
141
'the router will not be kept in sync with the current URL'
141
142
) ;
143
+
144
+ location = new StaticLocation ( location ) ;
142
145
} else {
143
146
invariant (
144
147
canUseDOM || location . needsDOM === false ,
@@ -240,11 +243,6 @@ function createRouter(options) {
240
243
* a new URL onto the history stack.
241
244
*/
242
245
transitionTo : function ( to , params , query ) {
243
- invariant (
244
- typeof location !== 'string' ,
245
- 'You cannot use transitionTo with a static location'
246
- ) ;
247
-
248
246
var path = this . makePath ( to , params , query ) ;
249
247
250
248
if ( pendingTransition ) {
@@ -260,11 +258,6 @@ function createRouter(options) {
260
258
* the current URL in the history stack.
261
259
*/
262
260
replaceWith : function ( to , params , query ) {
263
- invariant (
264
- typeof location !== 'string' ,
265
- 'You cannot use replaceWith with a static location'
266
- ) ;
267
-
268
261
location . replace ( this . makePath ( to , params , query ) ) ;
269
262
} ,
270
263
@@ -280,11 +273,6 @@ function createRouter(options) {
280
273
* because we cannot reliably track history length.
281
274
*/
282
275
goBack : function ( ) {
283
- invariant (
284
- typeof location !== 'string' ,
285
- 'You cannot use goBack with a static location'
286
- ) ;
287
-
288
276
if ( History . length > 1 || location === RefreshLocation ) {
289
277
location . pop ( ) ;
290
278
return true ;
@@ -296,7 +284,7 @@ function createRouter(options) {
296
284
} ,
297
285
298
286
handleAbort : options . onAbort || function ( abortReason ) {
299
- if ( typeof location === 'string' )
287
+ if ( location instanceof StaticLocation )
300
288
throw new Error ( 'Unhandled aborted transition! Reason: ' + abortReason ) ;
301
289
302
290
if ( abortReason instanceof Cancellation ) {
@@ -431,17 +419,15 @@ function createRouter(options) {
431
419
}
432
420
} ;
433
421
434
- if ( typeof location === 'string' ) {
435
- Router . dispatch ( location , null ) ;
436
- } else {
422
+ if ( ! ( location instanceof StaticLocation ) ) {
437
423
if ( location . addChangeListener )
438
424
location . addChangeListener ( Router . handleLocationChange ) ;
439
425
440
426
this . isRunning = true ;
441
-
442
- // Bootstrap using the current path.
443
- this . refresh ( ) ;
444
427
}
428
+
429
+ // Bootstrap using the current path.
430
+ this . refresh ( ) ;
445
431
} ,
446
432
447
433
refresh : function ( ) {
0 commit comments