fully-react
Version:
React Server for Vite
32 lines (30 loc) • 1.21 kB
TypeScript
declare const REDIRECT_ERROR_CODE = "REDIRECT";
type RedirectError<U extends string> = Error & {
digest: `${typeof REDIRECT_ERROR_CODE};${U}`;
};
/**
* When used in a React server component, this will insert a meta tag to
* redirect the user to the target page. When used in a custom app route, it
* will serve a 302 to the caller.
*
* @param url the url to redirect to
*/
declare function redirect(url: string): never;
/**
* Checks an error to determine if it's an error generated by the
* `redirect(url)` helper.
*
* @param error the error that may reference a redirect error
* @returns true if the error is a redirect error
*/
declare function isRedirectError<U extends string>(error: any): error is RedirectError<U>;
/**
* Returns the encoded URL from the error if it's a RedirectError, null
* otherwise. Note that this does not validate the URL returned.
*
* @param error the error that may be a redirect error
* @return the url if the error was a redirect error
*/
declare function getURLFromRedirectError<U extends string>(error: RedirectError<U>): U;
declare function getURLFromRedirectError(error: any): string | null;
export { getURLFromRedirectError, isRedirectError, redirect };