Skip to content

Commit b5b4446

Browse files
committed
Don't break the back button when hard loading
- Add a test case for going back from error pages which don't have pjax, as described in issue #422 - When hard loading a url, set the back action to the page's url from before the request was made Fixes #422
1 parent e3a93c9 commit b5b4446

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

jquery.pjax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ function pjaxReload(container, options) {
383383
//
384384
// Returns nothing.
385385
function locationReplace(url) {
386-
window.history.replaceState(null, "", "#")
386+
window.history.replaceState(null, "", pjax.state.url)
387387
window.location.replace(url)
388388
}
389389

test/app.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def title(str)
8383
erb :boom, :layout => !pjax?
8484
end
8585

86+
get '/boom_sans_pjax.html' do
87+
status 500
88+
erb :boom_sans_pjax, :layout => false
89+
end
90+
8691
get '/:page.html' do
8792
erb :"#{params[:page]}", :layout => !pjax?
8893
end

test/unit/pjax.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,4 +1240,29 @@ if ($.support.pjax) {
12401240
})
12411241
})
12421242
})
1243+
1244+
asyncTest("handles going back to page after loading an error page", function() {
1245+
var frame = this.frame
1246+
var iframe = this.iframe
1247+
1248+
equal(frame.location.pathname, "/home.html")
1249+
equal(frame.document.title, "Home")
1250+
1251+
$(iframe).one("load", function() {
1252+
1253+
window.iframeLoad = function() {
1254+
equal(frame.location.pathname, "/home.html")
1255+
equal(frame.document.title, "Home")
1256+
1257+
start()
1258+
}
1259+
1260+
frame.history.back()
1261+
})
1262+
1263+
frame.$.pjax({
1264+
url: "boom_sans_pjax.html",
1265+
container: "#main"
1266+
})
1267+
})
12431268
}

test/views/boom_sans_pjax.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>500 sans pjax</title>
6+
</head>
7+
<body>
8+
<div id="main">
9+
<p>500 sans pjax</p>
10+
</div>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)