zerodevx / svelte-toast

Simple elegant toast notifications
https://zerodevx.github.io/svelte-toast/
ISC License
830 stars 49 forks source link

Destroy toast when page changed #94

Open thibault60000 opened 8 months ago

thibault60000 commented 8 months ago

Hi, I want to close a Toast used for confirmation with toast.push({ component: {...})

How it's possible to close toast if user page changed ? For now, toast persist..

Thanks :)

zerodevx commented 8 months ago

If you're using SvelteKit, you can hook onto beforeNavigate(), something like:

import { beforeNavigate } from '$app/navigation'
import { toast } from '@zerodevx/svelte-toast'

beforeNavigate(() => toast.pop(0))