@@ -225,7 +225,7 @@ function pjax(options) {
225
225
settings . timeout = 0
226
226
}
227
227
228
- options . requestUrl = parseURL ( settings . url ) . href
228
+ options . requestUrl = stripInternalParams ( parseURL ( settings . url ) . href )
229
229
}
230
230
231
231
options . complete = function ( xhr , textStatus ) {
@@ -366,7 +366,7 @@ function pjax(options) {
366
366
// Cache current container element before replacing it
367
367
cachePush ( pjax . state . id , context . clone ( ) . contents ( ) )
368
368
369
- window . history . pushState ( null , "" , stripPjaxParam ( options . requestUrl ) )
369
+ window . history . pushState ( null , "" , options . requestUrl )
370
370
}
371
371
372
372
fire ( 'pjax:start' , [ xhr , options ] )
@@ -544,16 +544,22 @@ function uniqueId() {
544
544
return ( new Date ) . getTime ( )
545
545
}
546
546
547
- // Internal: Strips _pjax param from url
547
+ // Internal: Strips named query param from url
548
548
//
549
549
// url - String
550
550
//
551
551
// Returns String.
552
- function stripPjaxParam ( url ) {
552
+ function stripParam ( url , name ) {
553
+ return url
554
+ . replace ( new RegExp ( '[?&]' + name + '=[^&]*' ) , '' )
555
+ . replace ( / [ ? & ] $ / , '' )
556
+ . replace ( / [ ? & ] / , '?' )
557
+ }
558
+
559
+ function stripInternalParams ( url ) {
560
+ url = stripParam ( url , '_pjax' )
561
+ url = stripParam ( url , '_' )
553
562
return url
554
- . replace ( / \? _ p j a x = [ ^ & ] + & ? / , '?' )
555
- . replace ( / _ p j a x = [ ^ & ] + & ? / , '' )
556
- . replace ( / [ \? & ] $ / , '' )
557
563
}
558
564
559
565
// Internal: Parse URL components and returns a Locationish object.
@@ -669,7 +675,8 @@ function extractContainer(data, xhr, options) {
669
675
670
676
// Prefer X-PJAX-URL header if it was set, otherwise fallback to
671
677
// using the original requested url.
672
- obj . url = stripPjaxParam ( xhr . getResponseHeader ( 'X-PJAX-URL' ) || options . requestUrl )
678
+ var serverUrl = xhr . getResponseHeader ( 'X-PJAX-URL' )
679
+ obj . url = serverUrl ? stripInternalParams ( serverUrl ) : options . requestUrl
673
680
674
681
// Attempt to parse response html into elements
675
682
if ( fullDocument ) {
0 commit comments