sveltekit-flash-message
Version:
Send temporary data to the next request after redirect. Works with both SSR and client.
72 lines (71 loc) • 4.72 kB
TypeScript
import type { Cookies, RequestEvent, ServerLoad, ServerLoadEvent } from '@sveltejs/kit';
import { redirect as redir } from '@sveltejs/kit';
import type { CookieSerializeOptions } from './cookie-es-main/index.js';
export declare const flashCookieOptions: CookieSerializeOptions;
/**
* @deprecated Renamed to loadFlash.
*/
export declare function loadFlashMessage<S extends ServerLoad, E extends ServerLoadEvent>(cb: S): (event: E) => Promise<ReturnType<S>>;
/**
* Retrieves the flash message from the previous request.
* Use as a wrapper around a top-level load function, usually in a +layout.server.ts file.
*/
export declare function loadFlash<S extends ServerLoad, E extends ServerLoadEvent>(cb: S): (event: E) => Promise<ReturnType<S>>;
export declare function _loadFlash<T extends ServerLoadEvent>(event: T): {
flash: App.PageData['flash'] | undefined;
};
export declare const load: typeof _loadFlash;
type RedirectStatus = Parameters<typeof redir>[0];
/**
* Redirect a request. When called during request handling, SvelteKit will return a redirect response.
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | ({} & number)} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
* @param {string | URL} location The location to redirect to.
* @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.
* @throws {Error} If the provided status is invalid.
* @return {never}
*/
export declare function redirect(status: RedirectStatus, location: string | URL): ReturnType<typeof redir>;
/**
* Redirect a request to the current URL, with HTTP status 303 and a flash message.
* When called during request handling, SvelteKit will return a redirect response.
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
* @param {App.PageData['flash']} message The flash message.
* @param {RequestEvent} event The event for the load function or form action.
* @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.
* @throws {Error} If the provided status is invalid.
* @return {never}
*/
export declare function redirect(message: App.PageData['flash'], event: RequestEvent): ReturnType<typeof redir>;
/**
* Redirect a request to a specific location, with HTTP status 303 and a flash message.
* When called during request handling, SvelteKit will return a redirect response.
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
* @param {string | URL} location The redirect URL/location.
* @param {App.PageData['flash']} message The flash message.
* @param {RequestEvent | Cookies} event The event for the load function or form action, or the cookies object from the RequestEvent.
* @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.
* @throws {Error} If the provided status is invalid.
* @return {never}
*/
export declare function redirect(location: string | URL, message: App.PageData['flash'], event: RequestEvent | Cookies): ReturnType<typeof redir>;
/**
* Redirect a request to a specific location, with a specific HTTP status and a flash message.
* If thrown during request handling, SvelteKit will return a redirect response.
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
* @param {string | URL} location The redirect URL/location.
* @param {App.PageData['flash']} message The flash message.
* @param {RequestEvent | Cookies} event The event for the load function or form action, or the cookies object from the RequestEvent.
* @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.
* @throws {Error} If the provided status is invalid.
* @return {never}
*/
export declare function redirect(status: RedirectStatus, location: string | URL, message: App.PageData['flash'], event: RequestEvent | Cookies): ReturnType<typeof redir>;
/**
* Set the flash message without redirecting, for example when validation fails in a form action.
* @param {App.PageData['flash']} message The flash message.
* @param {RequestEvent} event The event for the form action or load function.
*/
export declare function setFlash(message: App.PageData['flash'], event: RequestEvent | Cookies): void;
export {};