New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pjax without making a server request #381
Comments
+1 I am trying to do the same (I just need to fade an overlay to go back to the main main page and change url without breaking back/forward). Reloading the same main content just to change the url is overkill. I already tried to simulate a pjax cachepush followed by a pushstate with a manually created state but pjax:popstate is not firing. So is there a way to add a state that would trigger pjax:popstate manually ? @marczking did you come up with a solution ? |
Right now it's tricky to mix pjax stuff with manual pushState/popstate stuff. You shouldn't expect I'll leave this open as a reminder that we need to improve pjax in scenarios where you mix-n-match it with other pushState functionality. |
This kind of requirement usually smells of an anti-pattern. You generally only want pushstate updates when big changes happen (such as general content replacement). Anything smaller is usually a code smell. You don't want URLs acting as application state management tools. |
// disable and then re-enable to make sure our handler is before PJAX's
$.pjax.disable();
$(window).on('popstate', function (e) {
if (!needPjax()) {
$.pjax.disable();
e.stopImmediatePropagation();
// do your non-PJAX stuff here
$.pjax.enable();
}
});
$.pjax.enable(); |
But overall I'd love to be able to prevent fragment replacing if |
Sometimes I want to only change some small things with JS only for which I don't need to make a request to the server. I would still like to change the
history.pushState
though.When using
history.pushState
manually I get my wished behaviour, only problem is when navigating withback/forward
-buttonspjax:popstate
does not fire on the manually setpushstates
.So is there a way I can do this with pjax?
The text was updated successfully, but these errors were encountered: