metafizzy / infinite-scroll

📜 Automatically add next page
https://infinite-scroll.com
7.41k stars 1.74k forks source link

History breaking links when enabled #924

Closed denoise closed 3 years ago

denoise commented 3 years ago

I'm using Infinite Scroll loading the data from a JSON and it's working fine if I don't enable the history.

A problem occurs when I enable the history: 'replace' option that changes the page URL for the subfolder and path of my server-side script breaking all links and images.

Here is my init code:

$infiniteContainer = $('#resultsContainer').infiniteScroll({
    path: function() {
        return 'ajax/ajax.items.php?'
        + '&s=' + searchStr
        + '&cat=' + filterCat
        + '&sub=' + filterSubCat
        + '&order=' + orderBy
        + '&offset=' + this.pageIndex;
    },
    responseType: 'text',
    history: 'replace',
    loadOnScroll: true,
    checkLastPage: true
});

when I enable the history then my URL gets converted to:

mydomain.com/ajax/ajax.items.php?s=&cat=&sub=&order=&offset=1

and the URL should stay as mydomain.com/

How can I prevent infinite scroll to change the URL to the wrong path and just passing the variables I need for scrolling to a specific page?

agdgdh commented 3 years ago

I'm using Infinite Scroll loading the data from a JSON and it's working fine if I don't enable the history.

A problem occurs when I enable the history: 'replace' option that changes the page URL for the subfolder and path of my server-side script breaking all links and images.

Here is my init code:

$infiniteContainer = $('#resultsContainer').infiniteScroll({

path: function() {

    return 'ajax/ajax.items.php?'

    + '&s=' + searchStr

    + '&cat=' + filterCat

    + '&sub=' + filterSubCat

    + '&order=' + orderBy

    + '&offset=' + this.pageIndex;

},

responseType: 'text',

history: 'replace',

loadOnScroll: true,

checkLastPage: true

});

when I enable the history then my URL gets converted to:

mydomain.com/ajax/ajax.items.php?s=&cat=&sub=&order=&offset=1

and the URL should stay as mydomain.com/

How can I prevent infinite scroll to change the URL to the wrong path and just passing the variables I need for scrolling to a specific page?

desandro commented 3 years ago

How can I prevent infinite scroll to change the URL to the wrong path and just passing the variables I need for scrolling to a specific page?

Set history: false


history: false
// disable changing URL and browser history