inertia icon indicating copy to clipboard operation
inertia copied to clipboard

feat: Add `preserveUrl` option

Open xiCO2k opened this issue 3 years ago • 1 comments

Same PR as #1009 but with a rebase, messed up the other PR somehow 🤦 .

Hey guys, this PR adds an option to preserve the current url, this is specially useful when there is an infinite scroll pagination.

Example:

const loadMoreIntersect = ref();
const allPosts = ref(props.posts.data);

const load = () => {
    if (props.posts.next_page_url === null) {
        return;
    }

    Inertia.get(props.posts.next_page_url, {}, {
        preserveState: true,
        preserveScroll: true,
        preserveUrl: true,
        only: ['posts'],
        onSuccess: () => allPosts.value.push(...props.posts.data)
    })
}

onMounted(() => {
    const observer = new IntersectionObserver(
        entries => entries.forEach(entry => entry.isIntersecting && load()),
        { rootMargin: '-150px 0px 0px 0px' }
    );

    observer.observe(loadMoreIntersect.value)
});

Without the preserveUrl it adds the ?page=2 to the url and if the user refreshes the page it will just show the page=2 content instead of both pages.

Let me know what you guys think about this feature.

Thanks, Francisco.

xiCO2k avatar Aug 19 '22 16:08 xiCO2k

Hey @reinink, should I target the next branch on this PR?

Thanks.

xiCO2k avatar Sep 30 '22 17:09 xiCO2k

@reinink Should I do a rework on this PR for the v1 support?

xiCO2k avatar Jan 14 '23 21:01 xiCO2k