From 46608ba61d4b0f1e7c5589db7df2a2136e1bfc8f Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Thu, 5 Jun 2014 10:49:05 +0800 Subject: [PATCH 1/2] Only set pjax.state if pushing or replacing --- jquery.pjax.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index 0a9cb1e1..caac14f6 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -253,16 +253,15 @@ function pjax(options) { return } - pjax.state = { - id: options.id || uniqueId(), - url: container.url, - title: container.title, - container: context.selector, - fragment: options.fragment, - timeout: options.timeout - } - if (options.push || options.replace) { + pjax.state = { + id: options.id || uniqueId(), + url: container.url, + title: container.title, + container: context.selector, + fragment: options.fragment, + timeout: options.timeout + } window.history.replaceState(pjax.state, container.title, container.url) } @@ -318,7 +317,7 @@ function pjax(options) { // using the container and options of the link we're loading for the // back button to the initial page. This ensures good back button // behavior. - if (!pjax.state) { + if ((options.push || options.replace) && !pjax.state) { pjax.state = { id: uniqueId(), url: window.location.href, From 170dcc3a66053912de93edd536074cd3715e0ee5 Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Thu, 5 Jun 2014 11:25:17 +0800 Subject: [PATCH 2/2] Set options.replace true in popstate handler --- jquery.pjax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index caac14f6..f2d37026 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -252,7 +252,6 @@ function pjax(options) { locationReplace(container.url) return } - if (options.push || options.replace) { pjax.state = { id: options.id || uniqueId(), @@ -438,6 +437,7 @@ function onPjaxPopstate(event) { url: state.url, container: container, push: false, + replace: true, fragment: state.fragment, timeout: state.timeout, scrollTo: false