fix pjax, tested on my website

Signed-off-by: 天空Blond <hurui200320@skyblond.info>
This commit is contained in:
天空Blond 2021-02-01 11:50:39 +08:00
parent 13b81bc650
commit 7d3bc66a50
No known key found for this signature in database
GPG Key ID: 9775BB4954DCFA56

View File

@ -134,19 +134,25 @@ import { removeTrailingSlash } from '../lib/url';
const handlePush = (state, title, url) => { const handlePush = (state, title, url) => {
removeEvents(); removeEvents();
// url is not guaranteed
// thus calling `url.toString()` might causes exception, then break the pjax update
// track only if url is validate
if (url) {
currentRef = currentUrl;
const newUrl = url.toString();
currentRef = currentUrl; if (newUrl.substring(0, 4) === 'http') {
const newUrl = url.toString(); currentUrl = '/' + newUrl.split('/').splice(3).join('/');
} else {
if (newUrl.substring(0, 4) === 'http') { currentUrl = newUrl;
currentUrl = '/' + newUrl.split('/').splice(3).join('/'); }
} else { // this function under some framework might be called multiple times
currentUrl = newUrl; // thus only track if currentUrl and currentRef are not same
if (currentUrl !== currentRef) {
trackView(currentUrl, currentRef);
setTimeout(addEvents, 300);
}
} }
trackView(currentUrl, currentRef);
setTimeout(addEvents, 300);
}; };
/* Global */ /* Global */