Skip to content

Commit

Permalink
Merge pull request #150 from BrianLangevin/patch-1
Browse files Browse the repository at this point in the history
Change cancelling events example from "start" to "before"
  • Loading branch information
reinink authored Dec 31, 2020
2 parents b9a5304 + 690968a commit 5adbb52
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pages/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ document.removeEventListener('inertia:start', startEventListener)

## Cancelling events

Some events (`start`, `invalid`, `error`) support cancellation, allowing you to prevent Inertia's default behaviour. Just like native events, if only one event listener calls `event.preventDefault()`, the event will be cancelled.
Some events (`before`, `invalid`, `error`) support cancellation, allowing you to prevent Inertia's default behaviour. Just like native events, if only one event listener calls `event.preventDefault()`, the event will be cancelled.

```js
import { Inertia } from '@inertiajs/inertia'

Inertia.on('start', (event) => {
Inertia.on('before', (event) => {
if (!confirm('Are you sure you want to navigate away?')) {
event.preventDefault()
}
Expand All @@ -106,7 +106,7 @@ As a convenience, if you register your event listener using `Inertia.on()`, you
```js
import { Inertia } from '@inertiajs/inertia'

Inertia.on('start', (event) => {
Inertia.on('before', (event) => {
return confirm('Are you sure you want to navigate away?')
})
```
Expand Down

0 comments on commit 5adbb52

Please sign in to comment.