Open xiCO2k opened 2 months ago
@xiCO2k
Not sure if it's every getting merged because it's currently ambiguous if Inertia is still maintained, however as a workaround in the meantime I believe you could use the same After solution but simply restore the URL
// Just for reference of vars names
import { inertia, page, router } from '@inertiajs/svelte';
const currentUrl = $page.url;
// Taking you exemple here
router.get(props.posts.next_page_url, {}, {
preserveState: true, // Already the case by default normally
preserveScroll: true,
only: ['posts'],
onSuccess: () => {
allPosts.value.push(...props.posts.data);
// Magic here
window.history.replaceState({}, $page.title, currentUrl)
}
})
@james-em That is good hack, but I would love to have that supported by default.
I'd like to just thank you @xiCO2k for re-submitting this! I'm really looking forward to have this implemented in the package.
This PR adds an option to preserve the current url.
This is specially useful when there is an infinite scroll pagination.
Before
To the infinite scrolls using Inertia we had to do something similar to this:
After
This this addiction, we can take advantage of the
preserveUrl
option, and pass it on therouter.get
method, like this:Without the
preserveUrl
it adds the?page=2
to the url and if the user refreshes the page it will just show thepage=2
content instead of both pages.Let me know what you guys think about this feature.
Thanks, Francisco.