Send temporary data after redirect, usually from endpoints. Works with both SSR and client.
The SvelteKit Flash Message library is designed to pass temporary data to the next request in a SvelteKit application. It is particularly useful for displaying success or failure messages after a POST request, which should be shown on the redirected page rather than on the form itself. This functionality is commonly referred to as a “flash message” and is often seen in PHP apps. The library aims to make implementing flash messages in SvelteKit easier, encouraging well-behaved web apps that redirect after POST requests.
app.d.ts
(Typescript only): Add the type for the flash message to App.PageData
in src/app.d.ts
. The flash message can be a simple string or a more advanced data structure, as long as it is serializable.loadFlash
and wrap your load function with it. If you’re not using any load functions, create a src/routes/+layout.server.ts
file with the provided content.getFlash
in a layout or page component to display the flash message. getFlash
will return a store that can be used to access the message.redirect
from sveltekit-flash-message/server
and use it in load functions and form actions.The SvelteKit Flash Message library provides an easy way to implement flash messages in SvelteKit applications. It allows for the passing of temporary data to be displayed on the redirected page after a POST request. The library encourages well-behaved web apps that redirect after POST requests, making it easier to display success or failure messages to the user. The installation and usage guide provided in the documentation walks users through the necessary steps to integrate the library into their SvelteKit projects.