vojtech-dobes / history.nette.ajax.js

Adds History API support to nette.ajax.js addon!
30 stars 27 forks source link

Problem with loading last item in history #17

Open michallohnisky opened 10 years ago

michallohnisky commented 10 years ago

Hi, I have a problem with history. My steps:

  1. Load page 1 (url /page-1)
  2. Load page 2 by AJAX (url /page-2)
  3. Load page 3 by AJAX (url /page-3)
  4. Go back in history: url changes to /page-2, content of the page changes to page 2
  5. Go back in history: ISSUE: url changes to /page-1, BUT content of the page is not changed and remains content of page 2

So moving in history works as expected, but not with the oldest page (the page I load in normal way - not AJAX way).

Are the snippets from the oldest page saved in the history?

zipper commented 7 years ago

I have experienced similar problem and the reason was I had freshUrl script, which after page load calla window.history.replaceState. This overrides state which is used in popstate handler (the state was empty object). You can try to check on popstate handler, if the state contains all the required fields.

For finding out, if there's another call of replaceState in your code, you could do something like this (just copy paste on beginning of JS):

var foo = window.history.replaceState;
window.history.replaceState = function() {
  debugger;
  foo();
}

This will pause the execution of script whenever the replaceState is called.