From 9fcd1e7574197fa6e7ac000a030378d877cb8837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ben=20A=C3=AFm?= <48261497+GauBen@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:00:38 +0100 Subject: [PATCH] docs: add most common status codes to redirect() doc (#13301) --- .changeset/quick-crabs-camp.md | 5 +++++ packages/kit/src/exports/index.js | 8 ++++++++ packages/kit/types/index.d.ts | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 .changeset/quick-crabs-camp.md diff --git a/.changeset/quick-crabs-camp.md b/.changeset/quick-crabs-camp.md new file mode 100644 index 000000000000..b5f2404df29d --- /dev/null +++ b/.changeset/quick-crabs-camp.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +chore: add most common status codes to `redirect()` JS documentation diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index 5454a2e15e31..3b69f24de40e 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -84,6 +84,14 @@ export function isHttpError(e, status) { /** * 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. + * + * Most common status codes: + * * `303 See Other`: redirect as a GET request (often used after a form POST request) + * * `307 Temporary Redirect`: redirect will keep the request method + * * `308 Permanent Redirect`: redirect will keep the request method, SEO will be transferred to the new page + * + * [See all redirect status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages) + * * @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. diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index b80a53f668db..88e9c3e8936e 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1901,6 +1901,14 @@ declare module '@sveltejs/kit' { /** * 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. + * + * Most common status codes: + * * `303 See Other`: redirect as a GET request (often used after a form POST request) + * * `307 Temporary Redirect`: redirect will keep the request method + * * `308 Permanent Redirect`: redirect will keep the request method, SEO will be transferred to the new page + * + * [See all redirect status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages) + * * @param 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 location The location to redirect to. * @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.