MoOx / pjax

Easily enable fast Ajax navigation on any website (using pushState + xhr)
MIT License
1.43k stars 124 forks source link

Needs popstate option to resolve history issue #170

Closed sleddd closed 6 years ago

sleddd commented 6 years ago

If you use whenDOMReady and try hitting the back button, it won't fire using success | complete. To get whenDOMReady to fire when navigating with history (back | forward), you need to attach an event listener to popstate. (i.e. document.addEventListener('pjax:popstate', function(){ //do stuff });

If you alter the pjax library within the function that handles popstate at about line 53 with: trigger(document,"pjax:popstate", state.options)

Then you will be able to add in your custom code: document.addEventListener('pjax:popstate', whenDOMReady)

It will solve the DOM ready, etc... not firing on history issue.

I would suggest adding the pjax:popstate option...

BehindTheMath commented 6 years ago

What's wrong with the success or complete events?

BehindTheMath commented 6 years ago

The popstate handler calls loadUrl() to load the page, just like when you click a new link. Further down the callstack, the pjax:success and pjax:complete events should be triggered.

BehindTheMath commented 6 years ago

I don't understand the issue. Popstate should trigger the success and complete events. Did you try it and it wasn't triggered?

BehindTheMath commented 6 years ago

Please post your code that reproduces the issue, so I can try to debug it.

sleddd commented 6 years ago

All I can tell you, is that it does not always trigger with success/complete and reliably works with popstate. Thank you for your help, but I have resolved my issue.