finish
event was firing in the wrong sequence for cancelled visits (#290).before
global event and onBefore()
event callback (#290).start
global event and onStart()
event callback (#290).Inertia.reload()
method to always preserve the state and scroll position (#293).Inertia.replace()
method (#294).Previously, to cancel a visit, you would call event.preventDefault()
from a start
global event listener. You could also cancel a visit by returning false
from the onStart()
event callback. This is no longer possible with the start
event. Instead, you can now do this with the before
event:
import { Inertia } from '@inertiajs/inertia'
Inertia.on('before', (event) => {
return confirm('Are you sure you want to navigate away?')
})
This can also be done from the new onBefore()
event callback:
Inertia.delete(`/users/${user.id}`, {
onBefore: () => confirm('Are you sure you want to delete this user?'),
})
As well as from the Inertia link:
<inertia-link :href="`/users/${user.id}`" method="post" @before="confirmDelete">Delete user<inertia-link>
The Inertia.reload()
method exists as a shortcut to reload a page's props, similar to how location.reload()
works. However, unlike location.reload()
, this method was previously not preserving the scroll position. This release updates this method to now always preserve the scroll position. We've also updated the method to always preserve the component state. Previously this method had preserveState
set true
by default, but it could be overwritten via the options
. This is no longer possible.
The goal here is to underline the purpose of this method, which is to reload the current URL while maintaining the current component state (preserveState: true
) as well as the current scroll position (preserveScroll: true
). If you need different behaviour than this, simply use one of the other methods, such as Inertia.get()
, and manually set these options.
This release deprecates the Inertia.replace()
method. This method has numerous issues with it:
data
.preserveState: true
, without any indication that it's doing this.replace: true
(the whole purpose of this method) is actually very rare, since Inertia automatically does this for visits made to the same URL.For these reasons, we have deprecated it and will be removing it in an upcoming release. Here's how to update your apps:
// Before
Inertia.replace('/users', { data: { search: 'John' } })
// If you're visiting the same endpoint:
Inertia.get('/users', { search: 'John' })
// If you're visiting a different endpoint:
Inertia.get('/users', { search: 'John' }, { replace: true })
// If you need state preserved:
Inertia.get('/users', { search: 'John' }, { preserveState: true })
This release corresponds to the @inertiajs/progress
version 0.2.0
release, which updates the progress library to take advantage of the improved "finish" event handling. If you're using @inertiajs/progress
, be sure to upgrade to ^0.2.0
at the same time, otherwise you'll run into issues with the progress bar not being removed properly.