@@ -8,6 +8,7 @@ var ImitateBrowserBehavior = require('./behaviors/ImitateBrowserBehavior');
88var HashLocation = require ( './locations/HashLocation' ) ;
99var HistoryLocation = require ( './locations/HistoryLocation' ) ;
1010var RefreshLocation = require ( './locations/RefreshLocation' ) ;
11+ var StaticLocation = require ( './locations/StaticLocation' ) ;
1112var NavigationContext = require ( './NavigationContext' ) ;
1213var StateContext = require ( './StateContext' ) ;
1314var Scrolling = require ( './Scrolling' ) ;
@@ -139,6 +140,8 @@ function createRouter(options) {
139140 'You should not use a static location in a DOM environment because ' +
140141 'the router will not be kept in sync with the current URL'
141142 ) ;
143+
144+ location = new StaticLocation ( location ) ;
142145 } else {
143146 invariant (
144147 canUseDOM || location . needsDOM === false ,
@@ -240,11 +243,6 @@ function createRouter(options) {
240243 * a new URL onto the history stack.
241244 */
242245 transitionTo : function ( to , params , query ) {
243- invariant (
244- typeof location !== 'string' ,
245- 'You cannot use transitionTo with a static location'
246- ) ;
247-
248246 var path = this . makePath ( to , params , query ) ;
249247
250248 if ( pendingTransition ) {
@@ -260,11 +258,6 @@ function createRouter(options) {
260258 * the current URL in the history stack.
261259 */
262260 replaceWith : function ( to , params , query ) {
263- invariant (
264- typeof location !== 'string' ,
265- 'You cannot use replaceWith with a static location'
266- ) ;
267-
268261 location . replace ( this . makePath ( to , params , query ) ) ;
269262 } ,
270263
@@ -280,11 +273,6 @@ function createRouter(options) {
280273 * because we cannot reliably track history length.
281274 */
282275 goBack : function ( ) {
283- invariant (
284- typeof location !== 'string' ,
285- 'You cannot use goBack with a static location'
286- ) ;
287-
288276 if ( History . length > 1 || location === RefreshLocation ) {
289277 location . pop ( ) ;
290278 return true ;
@@ -296,7 +284,7 @@ function createRouter(options) {
296284 } ,
297285
298286 handleAbort : options . onAbort || function ( abortReason ) {
299- if ( typeof location === 'string' )
287+ if ( location instanceof StaticLocation )
300288 throw new Error ( 'Unhandled aborted transition! Reason: ' + abortReason ) ;
301289
302290 if ( abortReason instanceof Cancellation ) {
@@ -431,17 +419,15 @@ function createRouter(options) {
431419 }
432420 } ;
433421
434- if ( typeof location === 'string' ) {
435- Router . dispatch ( location , null ) ;
436- } else {
422+ if ( ! ( location instanceof StaticLocation ) ) {
437423 if ( location . addChangeListener )
438424 location . addChangeListener ( Router . handleLocationChange ) ;
439425
440426 this . isRunning = true ;
441-
442- // Bootstrap using the current path.
443- this . refresh ( ) ;
444427 }
428+
429+ // Bootstrap using the current path.
430+ this . refresh ( ) ;
445431 } ,
446432
447433 refresh : function ( ) {
0 commit comments