@@ -221,7 +221,7 @@ function pjax(options) {
221221
222222 var allowed = fire ( 'pjax:error' , [ xhr , textStatus , errorThrown , options ] )
223223 if ( options . type == 'GET' && textStatus !== 'abort' && allowed ) {
224- locationReplace ( container . url )
224+ hardLoad ( container . url )
225225 }
226226 }
227227
@@ -238,16 +238,17 @@ function pjax(options) {
238238
239239 // If there is a layout version mismatch, hard load the new url
240240 if ( currentVersion && latestVersion && currentVersion !== latestVersion ) {
241- locationReplace ( container . url )
241+ hardLoad ( container . url )
242242 return
243243 }
244244
245245 // If the new response is missing a body, hard load the page
246246 if ( ! container . contents ) {
247- locationReplace ( container . url )
247+ hardLoad ( container . url )
248248 return
249249 }
250250
251+ // Update browser location and history
251252 pjax . state = {
252253 id : options . id || uniqueId ( ) ,
253254 url : container . url ,
@@ -257,7 +258,9 @@ function pjax(options) {
257258 timeout : options . timeout
258259 }
259260
260- if ( options . push || options . replace ) {
261+ if ( options . push ) {
262+ window . history . pushState ( pjax . state , container . title , container . url )
263+ } else if ( options . replace ) {
261264 window . history . replaceState ( pjax . state , container . title , container . url )
262265 }
263266
@@ -335,8 +338,6 @@ function pjax(options) {
335338 if ( options . push && ! options . replace ) {
336339 // Cache current container element before replacing it
337340 cachePush ( pjax . state . id , context . clone ( ) . contents ( ) )
338-
339- window . history . pushState ( null , "" , stripPjaxParam ( options . requestUrl ) )
340341 }
341342
342343 fire ( 'pjax:start' , [ xhr , options ] )
@@ -360,15 +361,20 @@ function pjaxReload(container, options) {
360361 return pjax ( $ . extend ( defaults , optionsFor ( container , options ) ) )
361362}
362363
363- // Internal: Hard replace current state with url.
364- //
365- // Work for around WebKit
366- // https://bugs.webkit.org/show_bug.cgi?id=93506
364+ // Internal: Hard load a URL, optionally replacing the current
365+ // history instead of adding a new history item. Used to load
366+ // fallbacks, reload layout on version changes, etc.
367367//
368368// Returns nothing.
369- function locationReplace ( url ) {
370- window . history . replaceState ( null , "" , "#" )
371- window . location . replace ( url )
369+ function hardLoad ( url , replace ) {
370+ if ( ! ! replace ) {
371+ // Work for around WebKit
372+ // https://bugs.webkit.org/show_bug.cgi?id=93506
373+ window . history . replaceState ( null , "" , "#" )
374+ window . location . replace ( url )
375+ } else {
376+ window . location . assign ( url )
377+ }
372378}
373379
374380
@@ -451,7 +457,7 @@ function onPjaxPopstate(event) {
451457 // scroll position.
452458 container [ 0 ] . offsetHeight
453459 } else {
454- locationReplace ( location . href )
460+ hardLoad ( location . href , true )
455461 }
456462 }
457463 initialPop = false
0 commit comments