Skip to content

Commit

Permalink
Update test page
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Sep 7, 2016
1 parent 25bbc06 commit 883ec12
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,13 @@
<head>
<script src="/bundle.js"></script>
<script>
var createHistory = History.createHistory
var useBeforeUnload = History.useBeforeUnload
var createHistory = History.createBrowserHistory

var page = 0
var h = useBeforeUnload(createHistory)()
var h = createHistory()

h.listenBeforeUnload(function () {
return "Wait, don't leave yet!"
})

h.listenBefore(function (location, callback) {
var promptMessage = 'Are you sure you want to go to ' + location.pathname + '?'

if (Math.random() > 0.5) {
callback(promptMessage) // sync
} else {
setTimeout(function () {
callback(promptMessage) // async
}, 500)
}
h.block(function (location, action) {
return 'Are you sure you want to go to ' + location.path + '?'
})

h.listen(function (location) {
Expand All @@ -33,9 +20,8 @@
<body>
<p>Use the two buttons below to test normal transitions.</p>
<p>
<button onclick="page++; h.pushState({ page: page }, '/' + page)">history.pushState</button>
<button onclick="page++; h.push('/' + page, { page: page })">history.push</button>
<button onclick="h.goBack()">history.goBack</button>
</p>
<p>Close the tab to test <code>beforeunload</code> behavior.</p>
</body>
</html>

0 comments on commit 883ec12

Please sign in to comment.