Merge pull request #458 from hurui200320/fix-pjax

Fix broken pjax
This commit is contained in:
Mike Cao 2021-02-01 21:15:45 -08:00 committed by GitHub
commit 967c40b1d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,19 +134,25 @@ import { removeTrailingSlash } from '../lib/url';
const handlePush = (state, title, url) => {
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;
const newUrl = url.toString();
if (newUrl.substring(0, 4) === 'http') {
currentUrl = '/' + newUrl.split('/').splice(3).join('/');
} else {
currentUrl = newUrl;
if (newUrl.substring(0, 4) === 'http') {
currentUrl = '/' + newUrl.split('/').splice(3).join('/');
} else {
currentUrl = newUrl;
}
// this function under some framework might be called multiple times
// 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 */