inertia
inertia copied to clipboard
feat: Add `preserveUrl` option
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.
Hey @reinink, should I target the next branch on this PR?
Thanks.
@reinink Should I do a rework on this PR for the v1 support?